Problem/Motivation
Currently, when using the `graphql_compose` module in Drupal, fetching a list of nodes through GraphQL queries only returns the original language version of the nodes. This behavior poses a limitation for multilingual Drupal installations, where administrators need the ability to retrieve nodes in their respective translations. Furthermore, there is no built-in support for filtering nodes by `langcode`, which restricts the flexibility in managing multilingual content.
Apologies if this functionality does already exist and I've misread or misunderstood
Steps to reproduce
1. Install and enable the `graphql_compose` module.
2. Configure the GraphQL schema and enable the `Articles` type. This is a content type created as part of the next-drupal GraphQL tutorial (https://next-drupal.org/learn/graphql/configure-path-aliases).
3. Make a GraphQL query to fetch `nodeArticles`.
4. Observe that the returned nodes are only in the original language, even if the original languages differ, and do not include translations.
5. Attempt to filter the `nodeArticles` query by `langcode`.
6. Observe that there is no built-in support for filtering `nodeArticles` by `langcode`.
Example query
query MyQuery {
nodeArticles(first: 10) {
edges {
node {
id
langcode {
id
}
title
}
}
}
}
Result
Note that for this example I created two articles, one in each language as the original, then a translation for each. As far as I can tell at this stage, I'm unable to return the translation.
{
"data": {
"nodeArticles": {
"edges": [
{
"node": {
"id": "23af15bd-838f-4333-a434-da48d5035595",
"langcode": {
"id": "en"
},
"title": "qefqewf"
}
},
{
"node": {
"id": "3622974f-4eaa-4d54-930a-04aed99deda6",
"langcode": {
"id": "ja"
},
"title": "いいい"
}
}
]
}
}
}
Proposed resolution
To address these limitations and enable fetching of translated `nodeArticles` while also allowing filtering by `langcode`, the `graphql_compose` module could be enhanced by implementing the following changes:
- Extend the GraphQL query resolver for `nodeArticles` to include support for fetching translations based on the language context or fallback to the sites' default language.
- Introduce a new filter option that allows administrators to specify the desired `langcode` for filtering.
Remaining tasks
User interface changes
This feature request focuses on backend functionality and does not require any user interface changes.
API changes
The proposed feature introduces changes to the `graphql_compose` module's GraphQL query resolver for nodes to include support for fetching translations and filtering by `langcode`. Documentation updates will be necessary to reflect these changes.
Data model changes
No data model changes are required for this feature. The existing data model for remains intact, with the addition of translation fetching support and `langcode` filtering capability.