What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Using @inContext(language) with GraphQL Admin API

Using @inContext(language) with GraphQL Admin API

WollyMeister
Tourist
4 0 0

Hi all!

I am trying to retrieve orders in multiple languages, for now it is possible to retrieve it in default langauge using:

 

'''
query { 
    products(first:1, after:null) { 
        edges {
            cursor 
            node {
                title 
                description
            } 
        } 
    } 
}
'''

 

 

But I can not seem to get it working for a different language, I have tried a lot and read about @inContext, but when I use that I get the error:

 

'''
query @inContext(language:"DE") { 
    products(first:1, after:null) { 
        edges {
            cursor 
            node {
                title 
                description
            } 
        } 
    } 
}
'''
{'errors': [{'message': 'Directive @inContext is not defined', 'locations': [{'line': 2, 'column': 7}], 'path': ['query'], 'extensions': {'code': 'undefinedDirective', 'directiveName': 'inContext'}}]}

 

 

I read somewhere that @inContext only works for Storefront API, is this true? And if so, how can I select a different language for my use case?

Thanks in advance!

Replies 5 (5)

SBD_
Shopify Staff
1831 273 421

Hey @WollyMeister 

 

Here's an example of pulling out translations with the Admin API: https://shopify.dev/docs/api/admin-graphql/2023-07/queries/product#examples-Loading_translations_and...

Scott | Developer Advocate @ Shopify 

WollyMeister
Tourist
4 0 0

Thanks for the reply, I managed to get it working.

However, I tried the same for productVariants, but that does not work... Is it not possible to retrieve productVariants in multiple languages?

ShopifyDevSup
Shopify Staff
1453 238 525

Hey @WollyMeister

 

Translations are also available on variants as well https://shopify.dev/docs/api/admin-graphql/2023-07/objects/ProductVariant#field-productvariant-trans... 

Here's an example of an order query that will get the variant translations in German:


```

{
 order(id: "gid://shopify/Order/12345678910") {     
   lineItems(first: 10) {
       nodes {
           variant {
               id
               translations(locale: "de") {
                   key
                   value
               }
           }
       }
   }
 }
}

```

Hope that helps! 

 

- Kyle G.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

WollyMeister
Tourist
4 0 0

Thanks for the response?

I have a last question, is it possible to retrieve the default countryCode of a webshop using a query in graphql?

ShopifyDevSup
Shopify Staff
1453 238 525

Hey @WollyMeister , yes, that's available in the ShopAddress object https://shopify.dev/docs/api/admin-graphql/2023-10/objects/ShopAddress#field-shopaddress-countrycode...

 

- Kyle G.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog