Skip to content

Commit d214f4a

Browse files
committed
Added 'executeSync': promise free version of execute.
Fixes graphql#2610
1 parent 9735ac7 commit d214f4a

18 files changed

+162
-145
lines changed

src/execution/__tests__/abstract-test.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { describe, it } from 'mocha';
55

66
import invariant from '../../jsutils/invariant';
77

8+
import { parse } from '../../language/parser';
9+
810
import { GraphQLSchema } from '../../type/schema';
911
import { GraphQLString, GraphQLBoolean } from '../../type/scalars';
1012
import {
@@ -14,7 +16,7 @@ import {
1416
GraphQLUnionType,
1517
} from '../../type/definition';
1618

17-
import { graphqlSync } from '../../graphql';
19+
import { executeSync } from '../execute';
1820

1921
class Dog {
2022
name: string;
@@ -88,7 +90,7 @@ describe('Execute: Handles execution of abstract types', () => {
8890
types: [CatType, DogType],
8991
});
9092

91-
const query = `
93+
const document = parse(`
9294
{
9395
pets {
9496
name
@@ -100,11 +102,9 @@ describe('Execute: Handles execution of abstract types', () => {
100102
}
101103
}
102104
}
103-
`;
104-
105-
const result = graphqlSync({ schema, source: query });
105+
`);
106106

107-
expect(result).to.deep.equal({
107+
expect(executeSync({ schema, document })).to.deep.equal({
108108
data: {
109109
pets: [
110110
{
@@ -158,7 +158,7 @@ describe('Execute: Handles execution of abstract types', () => {
158158
}),
159159
});
160160

161-
const query = `{
161+
const document = parse(`{
162162
pets {
163163
... on Dog {
164164
name
@@ -169,11 +169,9 @@ describe('Execute: Handles execution of abstract types', () => {
169169
meows
170170
}
171171
}
172-
}`;
172+
}`);
173173

174-
const result = graphqlSync({ schema, source: query });
175-
176-
expect(result).to.deep.equal({
174+
expect(executeSync({ schema, document })).to.deep.equal({
177175
data: {
178176
pets: [
179177
{
@@ -256,7 +254,7 @@ describe('Execute: Handles execution of abstract types', () => {
256254
types: [CatType, DogType],
257255
});
258256

259-
const query = `
257+
const document = parse(`
260258
{
261259
pets {
262260
name
@@ -268,9 +266,9 @@ describe('Execute: Handles execution of abstract types', () => {
268266
}
269267
}
270268
}
271-
`;
269+
`);
272270

273-
const result = graphqlSync({ schema, source: query });
271+
const result = executeSync({ schema, document });
274272

275273
expect(result).to.deep.equal({
276274
data: {
@@ -359,7 +357,7 @@ describe('Execute: Handles execution of abstract types', () => {
359357
}),
360358
});
361359

362-
const query = `
360+
const document = parse(`
363361
{
364362
pets {
365363
... on Dog {
@@ -372,9 +370,9 @@ describe('Execute: Handles execution of abstract types', () => {
372370
}
373371
}
374372
}
375-
`;
373+
`);
376374

377-
const result = graphqlSync({ schema, source: query });
375+
const result = executeSync({ schema, document });
378376

379377
expect(result).to.deep.equal({
380378
data: {
@@ -430,9 +428,9 @@ describe('Execute: Handles execution of abstract types', () => {
430428
types: [fooObject],
431429
});
432430

433-
const result = graphqlSync({ schema, source: '{ foo { bar } }' });
431+
const document = parse('{ foo { bar } }');
434432

435-
expect(result).to.deep.equal({
433+
expect(executeSync({ schema, document })).to.deep.equal({
436434
data: { foo: null },
437435
errors: [
438436
{
@@ -470,9 +468,9 @@ describe('Execute: Handles execution of abstract types', () => {
470468
types: [fooObject],
471469
});
472470

473-
const result = graphqlSync({ schema, source: '{ foo { bar } }' });
471+
const document = parse('{ foo { bar } }');
474472

475-
expect(result).to.deep.equal({
473+
expect(executeSync({ schema, document })).to.deep.equal({
476474
data: { foo: null },
477475
errors: [
478476
{
@@ -538,7 +536,7 @@ describe('Execute: Handles execution of abstract types', () => {
538536
types: [CatType, DogType],
539537
});
540538

541-
const query = `
539+
const document = parse(`
542540
{
543541
pets {
544542
name
@@ -550,11 +548,9 @@ describe('Execute: Handles execution of abstract types', () => {
550548
}
551549
}
552550
}
553-
`;
551+
`);
554552

555-
const result = graphqlSync({ schema, source: query });
556-
557-
expect(result).to.deep.equal({
553+
expect(executeSync({ schema, document })).to.deep.equal({
558554
data: {
559555
pets: [
560556
{

src/execution/__tests__/directives-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { GraphQLSchema } from '../../type/schema';
99
import { GraphQLString } from '../../type/scalars';
1010
import { GraphQLObjectType } from '../../type/definition';
1111

12-
import { execute } from '../execute';
12+
import type { ExecutionResult } from '../execute';
13+
import { executeSync } from '../execute';
1314

1415
const schema = new GraphQLSchema({
1516
query: new GraphQLObjectType({
@@ -30,9 +31,9 @@ const rootValue = {
3031
},
3132
};
3233

33-
function executeTestQuery(query: string) {
34+
function executeTestQuery(query: string): ExecutionResult {
3435
const document = parse(query);
35-
return execute({ schema, document, rootValue });
36+
return executeSync({ schema, document, rootValue });
3637
}
3738

3839
describe('Execute: handles directives', () => {

0 commit comments

Comments
 (0)