- Issue created by @sumit_saini
- 🇮🇳India sumit_saini
Further debugging took me to src/Plugin/GraphQL/DataProducer/Route::resolve() where language option is not added to $url object just after determining the correct language. The language is being set in access check condition (after comparing the passed path $value with the generated path $target_url which is causing this issue) which seemed out of place. Moving it before generating $target_url seems to work correctly.
--- a/src/Plugin/GraphQL/DataProducer/Route.php +++ b/src/Plugin/GraphQL/DataProducer/Route.php @@ -247,7 +247,9 @@ class Route extends DataProducerPluginBase implements ContainerFactoryPluginInte } } - // Check URL access. + $negotiatedLanguage = $this->languageManager->getLanguage($negotiatedLangcode); + $url->setOption('language', $negotiatedLanguage); + $field->setContextValue('language', $negotiatedLangcode); $target_url = $url->toString(TRUE)->getGeneratedUrl(); // if language detection is domain based, remove domain from $target_url @@ -272,10 +274,8 @@ class Route extends DataProducerPluginBase implements ContainerFactoryPluginInte $access = $url->access(NULL, TRUE); $field->addCacheableDependency($access); + // Check URL access. if ($access->isAllowed()) { - $negotiatedLanguage = $this->languageManager->getLanguage($negotiatedLangcode); - $url->setOption('language', $negotiatedLanguage); - $field->setContextValue('language', $negotiatedLangcode); return $url; } else {
After above fix, EntityUrl and EntityCanonicalUrl are returning correct language data.
- Status changed to Needs review
about 1 year ago 2:20pm 10 October 2023 - last update
about 1 year ago run-tests.sh fatal error - 🇨🇭Switzerland ayalon
This is not the way to go. To get the translated contest, you have to provide the translation language when doing the GraphQL request.
This ensures, that also field label translations and all other dependencies are working correct.In short:
Do the above query with the alias '/fr/node-alias' against your API with http:/my-backend/fr/graphql as where 'graphql' is the endpoint you defined in your graphql server configuration.
We will not incorporate the proposed patch. Please adapt your frontend application to provide the correct language when querying the API. Thanks for understanding.
- Status changed to Closed: won't fix
11 months ago 8:04am 25 January 2024