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

Gateway over-merging fields of unioned types #3581

Merged
merged 3 commits into from Dec 5, 2019

Conversation

trevor-scheer
Copy link
Member

@trevor-scheer trevor-scheer commented Dec 4, 2019

This PR adds some granularity to how fields are keyed when we group them within a selection set. Previously, the field name was considered sufficient for merging selections (and it almost always is!). However, in the case that the parentType of these same-named fields is different, we most certainly should not group selections as it will result in invalid query plans.

The new test illustrates this edge case via two unioned types that share a same top-level field name. The gateway was incorrectly grouping these separate fields into the same selectionSet under the media field. By keying on parentType:responseName instead, the gateway will know better than to group two distinct media fields of different types.

@stejas
Copy link

stejas commented Dec 5, 2019

Hi @trevor-scheer - I think I have a fix for this. Let me know if this passes your test. f2cc553

The groupByResponseName function was insufficient for
determining the merge condition for selections. The parent type
name is also required for the merge condition, as it's possible
for them to differ.
@trevor-scheer
Copy link
Member Author

Hey @stejas, thanks for taking a stab at this one! In your test, department has the same return type in both unioned types, so it doesn't quite test the case I was trying to. I had to get a bit more specific by keying on both the response name and parent type.

@trevor-scheer trevor-scheer marked this pull request as ready for review December 5, 2019 19:30
@trevor-scheer trevor-scheer merged commit c17c7bb into master Dec 5, 2019
@trevor-scheer trevor-scheer deleted the trevor/gateway-unions-bug branch December 5, 2019 19:44
@stejas
Copy link

stejas commented Dec 5, 2019

Hi @trevor-scheer - Just looked at your fix! If I understand correctly, aren't our fixes effectively same? I am passing fieldsForParentType instead of fieldsForResponseName to completeField which is already grouped by both response name and parent type

trevor-scheer added a commit that referenced this pull request Dec 16, 2019
This commit cleans up and simplifies the approach taken by #3581
to prevent the gateway from over-merging fields of unioned types.

The correct information and groupings were already present in the
affected code, they just needed to be utilized correctly. Specifically,
the internal for loop yielding `fieldsForParentType` was not being
used - the less specifically grouped `fieldsForResponseName` was.

Co-authored-by: Tejas Shikhare <tshikhare@netflix.com>
trevor-scheer added a commit that referenced this pull request Dec 16, 2019
This commit cleans up and simplifies the approach taken by #3581
to prevent the gateway from over-merging fields of unioned types.

The correct information and groupings were already present in the
affected code, they just needed to be utilized correctly. Specifically,
the internal for loop yielding `fieldsForParentType` was not being
used - the less specifically grouped `fieldsForResponseName` was.

Co-authored-by: Tejas Shikhare <tshikhare@netflix.com>
@trevor-scheer
Copy link
Member Author

@stejas you're right! My apologies, I was a bit excited to land this fix and could have looked a bit more closely (though I recall running those changes previously against my test and seeing failures 🤔 I'll chalk it up to an error on my end, since your changes pass my test now). I'll await your response on #3616 about landing your simplified changes.

trevor-scheer added a commit that referenced this pull request Jan 2, 2020
This commit cleans up and simplifies the approach taken by #3581
to prevent the gateway from over-merging fields of unioned types.

The correct information and groupings were already present in the
affected code, they just needed to be utilized correctly. Specifically,
the internal for loop yielding `fieldsForParentType` was not being
used - the less specifically grouped `fieldsForResponseName` was.

Co-authored-by: Tejas Shikhare <tshikhare@netflix.com>
abernix pushed a commit to apollographql/federation that referenced this pull request Sep 4, 2020
…rver#3581)

Group fields by response name AND parent type

The groupByResponseName function was insufficient for
determining the merge condition for selections. The parent type
name is also required for the merge condition, as it's possible
for them to differ.
Apollo-Orig-Commit-AS: apollographql/apollo-server@c17c7bb
abernix pushed a commit to apollographql/federation that referenced this pull request Sep 4, 2020
This commit cleans up and simplifies the approach taken by apollographql/apollo-server#3581
to prevent the gateway from over-merging fields of unioned types.

The correct information and groupings were already present in the
affected code, they just needed to be utilized correctly. Specifically,
the internal for loop yielding `fieldsForParentType` was not being
used - the less specifically grouped `fieldsForResponseName` was.

Co-authored-by: Tejas Shikhare <tshikhare@netflix.com>
Apollo-Orig-Commit-AS: apollographql/apollo-server@61e6941
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants