Skip to content

Test: Cleanup unneeded returns and async/await #1310

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

Merged
merged 2 commits into from
Apr 18, 2018
Merged
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
94 changes: 43 additions & 51 deletions src/execution/__tests__/executor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Execute: Handles basic execution tasks', () => {
).to.throw('Expected undefined to be a GraphQL schema.');
});

it('accepts an object with named properties as arguments', async () => {
it('accepts an object with named properties as arguments', () => {
const doc = 'query Example { a }';

const data = 'rootValue';
Expand All @@ -60,7 +60,7 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const result = await execute({
const result = execute({
schema,
document: parse(doc),
rootValue: data,
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('Execute: Handles basic execution tasks', () => {
).to.deep.equal(expected);
});

it('merges parallel fragments', async () => {
it('merges parallel fragments', () => {
const ast = parse(`
{ a, ...FragOne, ...FragTwo }

Expand All @@ -241,7 +241,7 @@ describe('Execute: Handles basic execution tasks', () => {
});
const schema = new GraphQLSchema({ query: Type });

expect(await execute(schema, ast)).to.deep.equal({
expect(execute(schema, ast)).to.deep.equal({
data: {
a: 'Apple',
b: 'Banana',
Expand All @@ -258,7 +258,7 @@ describe('Execute: Handles basic execution tasks', () => {
});
});

it('provides info about current execution state', async () => {
it('provides info about current execution state', () => {
const ast = parse('query ($var: String) { result: test }');

let info;
Expand All @@ -279,7 +279,7 @@ describe('Execute: Handles basic execution tasks', () => {

const rootValue = { root: 'val' };

await execute(schema, ast, rootValue, null, { var: 123 });
execute(schema, ast, rootValue, null, { var: 123 });

expect(Object.keys(info)).to.deep.equal([
'fieldName',
Expand Down Expand Up @@ -307,7 +307,7 @@ describe('Execute: Handles basic execution tasks', () => {
expect(info.variableValues).to.deep.equal({ var: '123' });
});

it('threads root value context correctly', async () => {
it('threads root value context correctly', () => {
const doc = 'query Example { a }';

const data = {
Expand All @@ -330,12 +330,12 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

await execute(schema, parse(doc), data);
execute(schema, parse(doc), data);

expect(resolvedRootValue.contextThing).to.equal('thing');
});

it('correctly threads arguments', async () => {
it('correctly threads arguments', () => {
const doc = `
query Example {
b(numArg: 123, stringArg: "foo")
Expand All @@ -362,7 +362,7 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

await execute(schema, parse(doc));
execute(schema, parse(doc));

expect(resolvedArgs.numArg).to.equal(123);
expect(resolvedArgs.stringArg).to.equal('foo');
Expand Down Expand Up @@ -603,7 +603,7 @@ describe('Execute: Handles basic execution tasks', () => {
});
});

it('Full response path is included for non-nullable fields', async () => {
it('Full response path is included for non-nullable fields', () => {
const A = new GraphQLObjectType({
name: 'A',
fields: () => ({
Expand Down Expand Up @@ -650,7 +650,7 @@ describe('Execute: Handles basic execution tasks', () => {
}
`;

const result = await execute(schema, parse(query));
const result = execute(schema, parse(query));
expect(result).to.deep.equal({
data: {
nullableA: {
Expand All @@ -667,7 +667,7 @@ describe('Execute: Handles basic execution tasks', () => {
});
});

it('uses the inline operation if no operation name is provided', async () => {
it('uses the inline operation if no operation name is provided', () => {
const doc = '{ a }';
const data = { a: 'b' };
const ast = parse(doc);
Expand All @@ -680,12 +680,12 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const result = await execute(schema, ast, data);
const result = execute(schema, ast, data);

expect(result).to.deep.equal({ data: { a: 'b' } });
});

it('uses the only operation if no operation name is provided', async () => {
it('uses the only operation if no operation name is provided', () => {
const doc = 'query Example { a }';
const data = { a: 'b' };
const ast = parse(doc);
Expand All @@ -698,12 +698,12 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const result = await execute(schema, ast, data);
const result = execute(schema, ast, data);

expect(result).to.deep.equal({ data: { a: 'b' } });
});

it('uses the named operation if operation name is provided', async () => {
it('uses the named operation if operation name is provided', () => {
const doc = 'query Example { first: a } query OtherExample { second: a }';
const data = { a: 'b' };
const ast = parse(doc);
Expand All @@ -716,12 +716,12 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const result = await execute(schema, ast, data, null, null, 'OtherExample');
const result = execute(schema, ast, data, null, null, 'OtherExample');

expect(result).to.deep.equal({ data: { second: 'b' } });
});

it('provides error if no operation is provided', async () => {
it('provides error if no operation is provided', () => {
const doc = 'fragment Example on Type { a }';
const data = { a: 'b' };
const ast = parse(doc);
Expand All @@ -734,13 +734,13 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const result = await execute(schema, ast, data);
const result = execute(schema, ast, data);
expect(result).to.deep.equal({
errors: [{ message: 'Must provide an operation.' }],
});
});

it('errors if no op name is provided with multiple operations', async () => {
it('errors if no op name is provided with multiple operations', () => {
const doc = 'query Example { a } query OtherExample { a }';
const data = { a: 'b' };
const ast = parse(doc);
Expand All @@ -753,7 +753,7 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const result = await execute(schema, ast, data);
const result = execute(schema, ast, data);
expect(result).to.deep.equal({
errors: [
{
Expand All @@ -764,7 +764,7 @@ describe('Execute: Handles basic execution tasks', () => {
});
});

it('errors if unknown operation name is provided', async () => {
it('errors if unknown operation name is provided', () => {
const doc = 'query Example { a } query OtherExample { a }';
const ast = parse(doc);
const schema = new GraphQLSchema({
Expand All @@ -776,7 +776,7 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const result = await execute({
const result = execute({
schema,
document: ast,
operationName: 'UnknownExample',
Expand All @@ -786,7 +786,7 @@ describe('Execute: Handles basic execution tasks', () => {
});
});

it('uses the query schema for queries', async () => {
it('uses the query schema for queries', () => {
const doc = 'query Q { a } mutation M { c } subscription S { a }';
const data = { a: 'b', c: 'd' };
const ast = parse(doc);
Expand All @@ -811,12 +811,12 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const queryResult = await execute(schema, ast, data, null, {}, 'Q');
const queryResult = execute(schema, ast, data, null, {}, 'Q');

expect(queryResult).to.deep.equal({ data: { a: 'b' } });
});

it('uses the mutation schema for mutations', async () => {
it('uses the mutation schema for mutations', () => {
const doc = 'query Q { a } mutation M { c }';
const data = { a: 'b', c: 'd' };
const ast = parse(doc);
Expand All @@ -835,12 +835,12 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const mutationResult = await execute(schema, ast, data, null, {}, 'M');
const mutationResult = execute(schema, ast, data, null, {}, 'M');

expect(mutationResult).to.deep.equal({ data: { c: 'd' } });
});

it('uses the subscription schema for subscriptions', async () => {
it('uses the subscription schema for subscriptions', () => {
const doc = 'query Q { a } subscription S { a }';
const data = { a: 'b', c: 'd' };
const ast = parse(doc);
Expand All @@ -859,7 +859,7 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const subscriptionResult = await execute(schema, ast, data, null, {}, 'S');
const subscriptionResult = execute(schema, ast, data, null, {}, 'S');

expect(subscriptionResult).to.deep.equal({ data: { a: 'b' } });
});
Expand Down Expand Up @@ -920,7 +920,7 @@ describe('Execute: Handles basic execution tasks', () => {
expect(Object.keys(result.data)).to.deep.equal(['a', 'b', 'c', 'd', 'e']);
});

it('Avoids recursion', async () => {
it('Avoids recursion', () => {
const doc = `
query Q {
a
Expand All @@ -944,12 +944,12 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const queryResult = await execute(schema, ast, data, null, {}, 'Q');
const queryResult = execute(schema, ast, data, null, {}, 'Q');

expect(queryResult).to.deep.equal({ data: { a: 'b' } });
});

it('does not include illegal fields in output', async () => {
it('does not include illegal fields in output', () => {
const doc = `mutation M {
thisIsIllegalDontIncludeMe
}`;
Expand All @@ -969,14 +969,14 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const mutationResult = await execute(schema, ast);
const mutationResult = execute(schema, ast);

expect(mutationResult).to.deep.equal({
data: {},
});
});

it('does not include arguments that were not set', async () => {
it('does not include arguments that were not set', () => {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Type',
Expand All @@ -997,7 +997,7 @@ describe('Execute: Handles basic execution tasks', () => {
});

const query = parse('{ field(a: true, c: false, e: 0) }');
const result = await execute(schema, query);
const result = execute(schema, query);

expect(result).to.deep.equal({
data: {
Expand All @@ -1006,7 +1006,7 @@ describe('Execute: Handles basic execution tasks', () => {
});
});

it('fails when an isTypeOf check is not met', async () => {
it('fails when an isTypeOf check is not met', () => {
class Special {
constructor(value) {
this.value = value;
Expand Down Expand Up @@ -1045,7 +1045,7 @@ describe('Execute: Handles basic execution tasks', () => {
const value = {
specials: [new Special('foo'), new NotSpecial('bar')],
};
const result = await execute(schema, query, value);
const result = execute(schema, query, value);

expect(result).to.deep.equal({
data: {
Expand All @@ -1062,7 +1062,7 @@ describe('Execute: Handles basic execution tasks', () => {
});
});

it('executes ignoring invalid non-executable definitions', async () => {
it('executes ignoring invalid non-executable definitions', () => {
const query = parse(`
{ foo }

Expand All @@ -1078,16 +1078,16 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const result = await execute(schema, query);
const result = execute(schema, query);
expect(result).to.deep.equal({
data: {
foo: null,
},
});
});

it('uses a custom field resolver', async () => {
const query = parse('{ foo }');
it('uses a custom field resolver', () => {
const document = parse('{ foo }');

const schema = new GraphQLSchema({
query: new GraphQLObjectType({
Expand All @@ -1103,15 +1103,7 @@ describe('Execute: Handles basic execution tasks', () => {
return info.fieldName;
}

const result = await execute(
schema,
query,
null,
null,
null,
null,
customResolver,
);
const result = execute({ schema, document, fieldResolver: customResolver });

expect(result).to.deep.equal({ data: { foo: 'foo' } });
});
Expand Down
22 changes: 6 additions & 16 deletions src/execution/__tests__/mutations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,13 @@ describe('Execute: Handles mutation execution ordering', () => {

const mutationResult = await execute(schema, parse(doc), new Root(6));

return expect(mutationResult).to.deep.equal({
expect(mutationResult).to.deep.equal({
data: {
first: {
theNumber: 1,
},
second: {
theNumber: 2,
},
third: {
theNumber: 3,
},
fourth: {
theNumber: 4,
},
fifth: {
theNumber: 5,
},
first: { theNumber: 1 },
second: { theNumber: 2 },
third: { theNumber: 3 },
fourth: { theNumber: 4 },
fifth: { theNumber: 5 },
},
});
});
Expand Down
Loading