-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gateway over-merging fields of unioned types (#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.
- Loading branch information
1 parent
e3d3b90
commit c17c7bb
Showing
4 changed files
with
103 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/apollo-gateway/src/__tests__/integration/unions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import gql from 'graphql-tag'; | ||
import { astSerializer, queryPlanSerializer } from '../../snapshotSerializers'; | ||
import { execute } from '../execution-utils'; | ||
|
||
expect.addSnapshotSerializer(astSerializer); | ||
expect.addSnapshotSerializer(queryPlanSerializer); | ||
|
||
it('handles multiple union type conditions that share a response name (media)', async () => { | ||
const query = gql` | ||
query { | ||
content { | ||
...Audio | ||
... on Video { | ||
media { | ||
aspectRatio | ||
} | ||
} | ||
} | ||
} | ||
fragment Audio on Audio { | ||
media { | ||
url | ||
} | ||
} | ||
`; | ||
|
||
const { queryPlan, errors } = await execute( | ||
[ | ||
{ | ||
name: 'contentService', | ||
typeDefs: gql` | ||
extend type Query { | ||
content: Content | ||
} | ||
union Content = Audio | Video | ||
type Audio { | ||
media: AudioURL | ||
} | ||
type AudioURL { | ||
url: String | ||
} | ||
type Video { | ||
media: VideoAspectRatio | ||
} | ||
type VideoAspectRatio { | ||
aspectRatio: String | ||
} | ||
`, | ||
resolvers: { | ||
Query: {}, | ||
}, | ||
}, | ||
], | ||
{ query }, | ||
); | ||
|
||
expect(errors).toBeUndefined(); | ||
expect(queryPlan).toMatchInlineSnapshot(` | ||
QueryPlan { | ||
Fetch(service: "contentService") { | ||
{ | ||
content { | ||
__typename | ||
... on Audio { | ||
media { | ||
url | ||
} | ||
} | ||
... on Video { | ||
media { | ||
aspectRatio | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters