You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
GraphQL translations are not working with GET requests.
To Reproduce
Steps to reproduce the behaviour:
Translate any string in a resolver
Add .csv translation files in the i18n folder under your module
Make a GET request for the GraphQL query that should return the translated string
Observe that the string is not translated
Make a POST request for the same query and observe that the string is now translated
Expected behaviour
The string should be translated for both GET and POST requests.
Screenshots
As you can see in the screenshot, we are making a POST request through GraphQL Playground and it's returning the expected result. But the same query with the GET request in the FE is returning non-translated strings.
Additional context
After some time spent investigating the issue, I found the root cause of it.
There are two plugins for the same \Magento\GraphQl\Controller\GraphQl::dispatch method and the one that's responsible for initializing the GraphQl translations (\ScandiPWA\CatalogGraphQl\Plugin\InitGraphQlTranslations::beforeDispatch) is not executed for GET requests because the other one (\ScandiPWA\PersistedQuery\Plugin\PersistedQuery::aroundDispatch) is called before and completely overrides the original method for GET and PUT requests.
I resolved this issue in the project that I am working on right now by overriding the plugin declarations in my module and adding a sortOrder like this:
Describe the bug
GraphQL translations are not working with GET requests.
To Reproduce
Steps to reproduce the behaviour:
Expected behaviour
The string should be translated for both GET and POST requests.
Screenshots
As you can see in the screenshot, we are making a POST request through GraphQL Playground and it's returning the expected result. But the same query with the GET request in the FE is returning non-translated strings.
Additional context
After some time spent investigating the issue, I found the root cause of it.
There are two plugins for the same
\Magento\GraphQl\Controller\GraphQl::dispatch
method and the one that's responsible for initializing the GraphQl translations (\ScandiPWA\CatalogGraphQl\Plugin\InitGraphQlTranslations::beforeDispatch
) is not executed for GET requests because the other one (\ScandiPWA\PersistedQuery\Plugin\PersistedQuery::aroundDispatch
) is called before and completely overrides the original method for GET and PUT requests.I resolved this issue in the project that I am working on right now by overriding the plugin declarations in my module and adding a
sortOrder
like this:I hope this helps!
The text was updated successfully, but these errors were encountered: