I am a bit new to GraphQl and trying to create a Shopify app to translate shops. So, each language in Shopify has its own tag (English: en, French: fr, etc) and some has tags with hyphen, like Simplified Chinese - “zh-CN”. And when I am trying to parse it through this method:
def build_resource_translation_query(main_query)
query_locales_translations = @shop_short_locales.map do |locale|
query_locale_translation(locale)
end.join
query_get_locales_translations = main_query.dup
query_get_locales_translations.gsub!(/<query_locales_translations>/, query_locales_translations)
end
It gives me out this error:
#<GraphQL::ParseError: Parse error on "-" (error) at [12, 3]>
All because of the Simplified Chinese tag (zh-CN). Those tags are taken from @Anonymous _short_locales, there’s how I get them:
def shop_short_locales
Locale.shop_locales.map { |l| l['locale'] }
end
And here is part of Locale class:
GET_SHOP_LOCALES = <<-GRAPHQL
{
shopLocales {
locale
primary
published
}
}
GRAPHQL
def shop_locales
Locale.new.graphql_query_exec(GET_SHOP_LOCALES).original_hash['data']['shopLocales']
end
I’ve tried just to remove hyphens from shop_short_locales with gsub! and it allowed me to enter the page with Chinese language but it did not save objects when I update them, obviously because of difference in tags that I parse and tags in GraphQl “zh-CN” =/= “zhCN”