Skip to content

Refactor executeOperation #883

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 1 commit into from
May 26, 2017
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
74 changes: 48 additions & 26 deletions src/execution/__tests__/executor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ describe('Execute: Handles basic execution tasks', () => {
expect(result).to.deep.equal({ data: { second: 'b' } });
});

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

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

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

expect(() => execute(schema, ast, data)).to.throw(
'Must provide operation name if query contains multiple operations.'
);
const result = await execute(schema, ast, data);
expect(result).to.deep.equal({
errors: [
{
message: 'Must provide operation name if query contains ' +
'multiple operations.',
locations: undefined,
path: undefined,
}
]
});
});

it('throws if unknown operation name is provided', () => {
it('throws if unknown operation name is provided', async () => {
const doc = 'query Example { a } query OtherExample { a }';
const data = { a: 'b' };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
Expand All @@ -661,11 +675,20 @@ describe('Execute: Handles basic execution tasks', () => {
})
});

expect(() =>
execute(schema, ast, data, null, null, 'UnknownExample')
).to.throw(
'Unknown operation named "UnknownExample".'
);
const result = await execute({
schema,
document: ast,
operationName: 'UnknownExample'
});
expect(result).to.deep.equal({
errors: [
{
message: 'Unknown operation named "UnknownExample".',
locations: undefined,
path: undefined,
}
]
});
});

it('uses the query schema for queries', async () => {
Expand Down Expand Up @@ -960,17 +983,16 @@ describe('Execute: Handles basic execution tasks', () => {
})
});

let caughtError;
try {
await execute(schema, query);
} catch (error) {
caughtError = error;
}

expect(caughtError).to.jsonEqual({
message:
'GraphQL cannot execute a request containing a ObjectTypeDefinition.',
locations: [ { line: 4, column: 7 } ]
const result = await execute(schema, query);
expect(result).to.deep.equal({
errors: [
{
message: 'GraphQL cannot execute a request containing a ' +
'ObjectTypeDefinition.',
locations: [ { line: 4, column: 7 } ],
path: undefined,
}
]
});
});

Expand Down
Loading