Can't find i18n fields in GraphQL after deploying document-internationalization plugin
GraphQL only exposes fields that are declared in your Studio schema and included in the deployed GraphQL API. So the i18n_* fields (or, with today's plugin, the language field) have to be defined on each translatable document type. After any schema change, run the GraphQL deploy again.
If you're on the legacy i18n_* setup (Studio v2)
The old document-internationalization setup stored hidden i18n_lang, i18n_base and i18n_refs fields on each translated document. They won't appear in GraphQL unless:
- They're declared in the
fieldsof every document type that hasi18n: true. Object types liketitleornavigationItemdon't need them. - Every reference points at a real type with
to. Use the translated document's own type, not'schema'. A reference without a validtoarray fails with "The reference type is missing or having an invalid value for the required 'to' property". - You redeploy the GraphQL API afterwards.
{ name: 'i18n_lang', type: 'string', hidden: true },
{ name: 'i18n_base', type: 'reference', hidden: true, to: [{ type: 'page' }] },
{
name: 'i18n_refs',
type: 'array',
hidden: true,
of: [{ type: 'reference', to: [{ type: 'page' }] }],
},Check what the base field actually holds in your documents (a single reference or an array) and match the schema to it. If they don't match, GraphQL returns null.
That setup is for Studio v2. On a current Studio, use the plugin model below.
Current approach: @sanity/document-internationalization
With today's plugin, each language is its own document. The plugin sets a language field on each document and creates a translation.metadata document that references all the language versions (Localization docs). No i18n_* fields are involved.
- Add a
languagestring field to each translatable document type, for example withoptions.listvalues like{title: 'English', value: 'en'}. - Redeploy GraphQL from the Studio folder. Schema changes are not picked up automatically (GraphQL docs):
npx sanity@latest graphql deploy- Filter by language with the generated
all<TypeName>query:
query {
allPage(where: { language: { eq: "en" } }) {
_id
title
language
}
}Some GraphQL limits to know about: string fields support eq, neq, in, nin and matches, but arrays can't be filtered. So you can't filter on a list of translation references, only on scalar fields like language. The legacy v1 endpoint still works, but dated endpoints like https://<projectId>.api.sanity.io/v2025-02-19/graphql/<dataset>/<tag> are current.
Getting the other translations of a document
The documented way is GROQ. Go from a document to its translation.metadata and follow the references:
*[_type == "page" && language == $language]{
title, slug, language,
"_translations": *[_type == "translation.metadata" && references(^._id)].translations[].value->{
title, slug, language
}
}According to the Sanity docs, the plugin's README has both GROQ and GraphQL query examples. Check it for the GraphQL version of this lookup for your plugin version.
Also note: v6 of the plugin moved the language identifier in the metadata translation entries from _key to a dedicated language field. If you upgrade, update any queries that filter on _key.
Show original thread58 replies
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.