Skip to content

Commit

Permalink
Added 'executeSync': promise free version of execute.
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jun 22, 2020
1 parent 9735ac7 commit 7cc7464
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 145 deletions.
48 changes: 22 additions & 26 deletions src/execution/__tests__/abstract-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { describe, it } from 'mocha';

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

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

import { GraphQLSchema } from '../../type/schema';
import { GraphQLString, GraphQLBoolean } from '../../type/scalars';
import {
Expand All @@ -14,7 +16,7 @@ import {
GraphQLUnionType,
} from '../../type/definition';

import { graphqlSync } from '../../graphql';
import { executeSync } from '../execute';

class Dog {
name: string;
Expand Down Expand Up @@ -88,7 +90,7 @@ describe('Execute: Handles execution of abstract types', () => {
types: [CatType, DogType],
});

const query = `
const document = parse(`
{
pets {
name
Expand All @@ -100,11 +102,9 @@ describe('Execute: Handles execution of abstract types', () => {
}
}
}
`;

const result = graphqlSync({ schema, source: query });
`);

expect(result).to.deep.equal({
expect(executeSync({ schema, document })).to.deep.equal({
data: {
pets: [
{
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('Execute: Handles execution of abstract types', () => {
}),
});

const query = `{
const document = parse(`{
pets {
... on Dog {
name
Expand All @@ -169,11 +169,9 @@ describe('Execute: Handles execution of abstract types', () => {
meows
}
}
}`;
}`);

const result = graphqlSync({ schema, source: query });

expect(result).to.deep.equal({
expect(executeSync({ schema, document })).to.deep.equal({
data: {
pets: [
{
Expand Down Expand Up @@ -256,7 +254,7 @@ describe('Execute: Handles execution of abstract types', () => {
types: [CatType, DogType],
});

const query = `
const document = parse(`
{
pets {
name
Expand All @@ -268,9 +266,9 @@ describe('Execute: Handles execution of abstract types', () => {
}
}
}
`;
`);

const result = graphqlSync({ schema, source: query });
const result = executeSync({ schema, document });

expect(result).to.deep.equal({
data: {
Expand Down Expand Up @@ -359,7 +357,7 @@ describe('Execute: Handles execution of abstract types', () => {
}),
});

const query = `
const document = parse(`
{
pets {
... on Dog {
Expand All @@ -372,9 +370,9 @@ describe('Execute: Handles execution of abstract types', () => {
}
}
}
`;
`);

const result = graphqlSync({ schema, source: query });
const result = executeSync({ schema, document });

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

const result = graphqlSync({ schema, source: '{ foo { bar } }' });
const document = parse('{ foo { bar } }');

expect(result).to.deep.equal({
expect(executeSync({ schema, document })).to.deep.equal({
data: { foo: null },
errors: [
{
Expand Down Expand Up @@ -470,9 +468,9 @@ describe('Execute: Handles execution of abstract types', () => {
types: [fooObject],
});

const result = graphqlSync({ schema, source: '{ foo { bar } }' });
const document = parse('{ foo { bar } }');

expect(result).to.deep.equal({
expect(executeSync({ schema, document })).to.deep.equal({
data: { foo: null },
errors: [
{
Expand Down Expand Up @@ -538,7 +536,7 @@ describe('Execute: Handles execution of abstract types', () => {
types: [CatType, DogType],
});

const query = `
const document = parse(`
{
pets {
name
Expand All @@ -550,11 +548,9 @@ describe('Execute: Handles execution of abstract types', () => {
}
}
}
`;
`);

const result = graphqlSync({ schema, source: query });

expect(result).to.deep.equal({
expect(executeSync({ schema, document })).to.deep.equal({
data: {
pets: [
{
Expand Down
7 changes: 4 additions & 3 deletions src/execution/__tests__/directives-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { GraphQLSchema } from '../../type/schema';
import { GraphQLString } from '../../type/scalars';
import { GraphQLObjectType } from '../../type/definition';

import { execute } from '../execute';
import type { ExecutionResult } from '../execute';
import { executeSync } from '../execute';

const schema = new GraphQLSchema({
query: new GraphQLObjectType({
Expand All @@ -30,9 +31,9 @@ const rootValue = {
},
};

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

describe('Execute: handles directives', () => {
Expand Down
Loading

0 comments on commit 7cc7464

Please sign in to comment.