Skip to content

Support @defer directive #2318

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

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
80 changes: 80 additions & 0 deletions src/execution/__tests__/directives-perf-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// @flow strict

import { expect } from 'chai';
import { it } from 'mocha';

import { parse } from '../../language/parser';

import { GraphQLSchema } from '../../type/schema';
import { GraphQLString } from '../../type/scalars';
import { GraphQLObjectType } from '../../type/definition';

import { execute } from '../execute';
import { forAwaitEach, isAsyncIterable } from 'iterall';

const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'TestType',
fields: {
a: { type: GraphQLString },
b: { type: GraphQLString },
},
}),
});

let count = 0;

const rootValue = {
a() {
return 'a';
},
b() {
count += 1;
return `b${count}`;
},
};

function executeTestQuery(query) {
const document = parse(query);
return execute({ schema, document, rootValue });
}

it('performance test, if the same field is deferred several times, its resolve is called only once', async () => {
const index = 100;
let fragString = '';
let fragElementString = '';
for (const i of Array.from(Array(index).keys())) {
fragString += `
...Frag${i} @defer(label: "Frag_b_defer${i}")
`;
fragElementString += `
fragment Frag${i} on TestType {
b
}
`;
}
const result = await executeTestQuery(`
query {
a
${fragString}
}
${fragElementString}
`);
expect(isAsyncIterable(result)).to.equal(true);
const results = [];
await forAwaitEach(((result: any): AsyncIterable<mixed>), value => {
results.push(value);
});

expect(results.length).to.equal(index + 1);
expect(results[0]).to.deep.equal({
data: { a: 'a' },
});
for (const i of Array.from(Array(index).keys())) {
expect(results[i + 1]).to.deep.equal({
data: { b: 'b1' },
label: `Frag_b_defer${i}`,
path: [],
});
}
});
Loading