fix(plugin-graphql): Fix association resolver for manyWay
nature.
#7959
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #4353 and all its duplicates.
Detailed description of the problem:
As said by @abanchev here the problem is at file services/type-definitions.js near line 184:
It turns out that in the case of a 3+ level nested query, the third level will not work because the obj is not populated with the
association.alias
so it enters the else block and add theassociation.via
in the query. But the problem is thatassociation.via
formanyWay
isundefined
. This will propagate and the code will be looking for something likeundefined_id
and throw the known error message:You can reproduce it in this repo that I have prepared: https://github.com/danieldspx/strapi-graphql-example (See the README)
The cause for this problem: As we all know well, if you want to fetch such a nested content like this (with the API endpoint), you need to overwrite your controller (see this stackoverflow awnser). For the GraphQL we do not have something like this. Overwriting your controller will not affect the GraphQL way of fetching the content, thus the problem persist independent of your controller (I have tested this).
Description of my solution:
As you can see I added one line in the switch case and then the problem is fixed because it fetches de data for the
association.alias
and everything works perfectly and you can go as many deepness levels as you want (as long you respect your depthLimit). This does not break other relations nature.