Using @inContext(language) with GraphQL Admin API

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!

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_localizations_of_a_product_s_title_and_description

1 Like

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?

Hey @WollyMeister !

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

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.
1 Like

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?

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

  • Kyle G.