[IMPLEMENTED] GraphQL default language

Is it currently possible to set the default language for GraphQL queries? Something like the X-Languages header offered as part of the REST API.

Including the language again and again for every field just seems rather cumbersome, especially when the language needs to be set based on a variable.

`{
  queryPeopleContents {
    data {
      name {
        ${language}
      }
      role {
        ${language}
      }
    }
  }
}`

Also, the X-Flatten header would be quite nice to have in order to make the queries even more simple.

Is there a reason why these headers (as well as the fallback language) have not been implemented for the GraphQL endpoint, while they are available for the REST API.

GraphQL has a strict schema. So what you define you should get out. We could make alternative endpoints where you define the language in another way.

I think a query for a specific language would be nice, which combines the functionality of X-Languages and X-Flatten.

For example:

queryPeopleContentsInLanguage(lang: "nl_NL") {
  data: {
    name: String,
    role: String,
  }
}

I think we generally only want to show the user a single language. So instead of querying all languages and filtering within our code, we should specify the language we want and only get that language. Since we get a single language, the result might as well be flattened.

This way, we can use string variables within the GraphQL query which is sent to the API. Using @include (docs) within the query doesn’t scale and querying all languages goes a bit against the principle of GraphQL (querying only the data you need).

Not sure if this is what you meant with “make alternative endpoints”. If so, yes, I think that would be a good idea.

2 Likes

Hi,

I am working on a version that introduces flatData to the model. It does exactly what you are looking for.

At least almost. The first version would still provide the language as header.

It is deployed to the cloud.