-
Notifications
You must be signed in to change notification settings - Fork 223
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
Querying the same relation multiple times as aliases with different args results in wrong data #481
Comments
I did some experiments in a fork, and stumbled upon the skipped test The best I could come up with for now is a workaround: kryops@f75a574
While this is still far from a viable solution, maybe it could be used as a starting point for a proper fix? |
Ah, I finally found #126, so it seems I created a duplicate 😕 |
I just recently ran into this issue as well. Its surprising that its a bug that's been around for years because it seems like its such a common use case. I can assist where needed to help get this fix out. |
While my workaround seems to work quite well for 1:n relationships, it seems to fail miserably for aliased 1:1 relationships because
|
I am closing this in favor of #126 |
Description
Hi there,
in a GraphQL query that uses aliases to query the same relation multiple times with different args, the relation is resolved only once, which results in wrong results for the other aliases.
Reproduction
table1
has a 1:1 or 1:n relation totable2
that uses args:Now I query the same relation twice with different args:
Expected Result:
Actual Result:
I did a bit of debugging, and these are my findings:
sqlJoin
, the first relation is not even joined -handleSelections
recognizes it asexistingNode
and overrides it with the second onesqlBatch
, the SQL queries are executed as expected, but the last result seems to overwrite the former ones when the results are stitched back togetherThe root issue seems to be that the GraphQL default resolver (that gets passed down the result from
join-monster
) expects the originalfieldName
as object property, and GraphQL handles the aliasing somewhere internally: https://github.com/graphql/graphql-js/blob/97c95124b17ec42b62917a65c94fd528c69c7cfe/src/execution/execute.ts#L1015.Thus,
join-monster
ignores the aliases and uses the original field names, which can lead to conflicts in this case.This is the result object that GraphQL currently receives from
join-monster
:In order to make this use case work, it might have to look something like this:
Is this something that can be fixed in
join-monster
? Is there a way to work around it?Thanks for your support!
Environment
join-monster@3.1.1
graphql@15.8.0
The text was updated successfully, but these errors were encountered: