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

fix(gateway): Correctly handle unions with nested conditions that have no possibleTypes #4071

Merged
merged 3 commits into from
May 8, 2020

Conversation

trevor-scheer
Copy link
Member

@trevor-scheer trevor-scheer commented May 6, 2020

Problem

The nested for loops within splitFields that utilize groupByResponseName and groupByParentType make a false assumption that the incoming fields are all valid. In this case, an "invalid" field is one with no possibleTypes.

In its current state, the splitFields function can consume an invalid field, leaving other valid, similarly-grouped fields ignored (only one will be taken). If an invalid field is consumed, the others will be ignored and the invalid field will subsequently be dropped, meaning the valid field is never represented due to the existence of an invalid field.

Solution

A field with no possibleTypes can be dropped / ignored from the query since the requested field exists within an impossible condition. Thus, we can skip the collectFields step altogether for fields which have no possibleTypes. The effect of skipping this step is that invalid fields are no longer represented within the splitFields function, thereby resolving the issue.

Fixes #3983

@trevor-scheer trevor-scheer requested review from jhampton and abernix May 6, 2020 02:08
@trevor-scheer trevor-scheer force-pushed the trevor/fix-nested-unions branch 3 times, most recently from 4e9579b to e23be54 Compare May 8, 2020 04:05
@trevor-scheer trevor-scheer force-pushed the trevor/fix-nested-unions branch from e23be54 to d242940 Compare May 8, 2020 04:06
.vscode/settings.json Outdated Show resolved Hide resolved
@trevor-scheer trevor-scheer merged commit e0858d8 into master May 8, 2020
@trevor-scheer trevor-scheer deleted the trevor/fix-nested-unions branch May 8, 2020 19:30
abernix pushed a commit to apollographql/federation that referenced this pull request Sep 4, 2020
…e no `possibleTypes` (apollographql/apollo-server#4071)

Skip collectFields for INLINE_FRAGMENTs and FRAGMENT_SPREADs when they have no possibleTypes.

A field with no possibleTypes can be dropped / ignored from the query since
the requested field exists within an impossible condition. Thus, we can skip
the collectFields step altogether for fields which have no possibleTypes. The
effect of skipping this step is that invalid fields are no longer represented
within the splitFields function, thereby resolving the issue.
Apollo-Orig-Commit-AS: apollographql/apollo-server@e0858d8
@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.

Gateway returning incorrect data when using Union type
2 participants