Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL translations are not working with GET requests #117

Open
niklavskatlaps opened this issue Nov 25, 2020 · 0 comments
Open

GraphQL translations are not working with GET requests #117

niklavskatlaps opened this issue Nov 25, 2020 · 0 comments
Assignees

Comments

@niklavskatlaps
Copy link

Describe the bug
GraphQL translations are not working with GET requests.

To Reproduce
Steps to reproduce the behaviour:

  1. Translate any string in a resolver
  2. Add .csv translation files in the i18n folder under your module
  3. Make a GET request for the GraphQL query that should return the translated string
  4. Observe that the string is not translated
  5. 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.

Screenshot at 18-41-22
Screenshot at 10-49-31

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:

<type name="Magento\GraphQl\Controller\GraphQl">
    <plugin name="graphql_init_translations" type="ScandiPWA\CatalogGraphQl\Plugin\InitGraphQlTranslations"
        sortOrder="10" />
    <plugin name="scandipwa_persisted_query" type="ScandiPWA\PersistedQuery\Plugin\PersistedQuery" 
        sortOrder="20" />
</type>

I hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants