The custom fields for document wide translation are not available in GraphQL by default because they have to be defined in the schema. However it is not possible to define "system" type fields in a Sanity schema, due to this we need to take some steps to make this work correctly:
- We need to change the field names to not start with underscores as these are reserved names.
const schema = {
i18n: {
fieldNames: {
lang: 'i18n_lang'
references: 'i18n_refs'
}
}
};
- We need to add them as actual fields in the schema
const i18n_refs_object = {
name: 'i18n_refs',
type: 'object',
fields: [{
type: 'string',
name: 'lang'
}, {
type: 'reference',
name: 'ref',
to: [{ type: 'homepage' }]
}]
};
const schema = {
type: 'schema',
fields: [
{
name: 'i18n_lang',
type: 'string',
hidden: true
},
{
name: 'i18n_refs',
type: 'array',
hidden: true,
of: [{
type: 'i18n_refs_object',
}]
}
]
}
This way the GraphQL deployment will consider the i18n_lang
and i18n_refs
properties as part of your structure and you will be able to query by them.