Skip to content

Commit

Permalink
Add test for consolidating grouped field sets properly into deferred …
Browse files Browse the repository at this point in the history
…fragments

Group field sets should be properly consolidated when some of the fields in a sibling defer are masked by parent fields.
  • Loading branch information
yaacovCR committed Dec 18, 2023
1 parent 2aedf25 commit eb6a0bf
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/execution/__tests__/defer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const anotherNestedObject = new GraphQLObjectType({

const hero = {
name: 'Luke',
lastName: 'SkyWalker',
id: 1,
friends,
nestedObject,
Expand Down Expand Up @@ -112,6 +113,7 @@ const heroType = new GraphQLObjectType({
fields: {
id: { type: GraphQLID },
name: { type: GraphQLString },
lastName: { type: GraphQLString },
nonNullName: { type: new GraphQLNonNull(GraphQLString) },
friends: {
type: new GraphQLList(friendType),
Expand Down Expand Up @@ -566,6 +568,58 @@ describe('Execute: defer directive', () => {
]);
});

it('Separately emits defer fragments with different labels with varying subfields with superimposed masked defer', async () => {
const document = parse(`
query HeroNameQuery {
... @defer(label: "DeferID") {
hero {
id
}
}
... @defer(label: "DeferName") {
hero {
name
lastName
... @defer {
lastName
}
}
}
}
`);
const result = await complete(document);
expectJSON(result).toDeepEqual([
{
data: {},
pending: [
{ id: '0', path: [], label: 'DeferID' },
{ id: '1', path: [], label: 'DeferName' },
],
hasNext: true,
},
{
incremental: [
{
data: { hero: {} },
id: '0',
},
{
data: { id: '1' },
id: '0',
subPath: ['hero'],
},
{
data: { name: 'Luke', lastName: 'SkyWalker' },
id: '1',
subPath: ['hero'],
},
],
completed: [{ id: '0' }, { id: '1' }],
hasNext: false,
},
]);
});

it('Separately emits defer fragments with different labels with varying subfields that return promises', async () => {
const document = parse(`
query HeroNameQuery {
Expand Down

0 comments on commit eb6a0bf

Please sign in to comment.