Skip to content

Commit

Permalink
Add tests confirming #319
Browse files Browse the repository at this point in the history
  • Loading branch information
leebyron committed Mar 22, 2016
1 parent 3ce90fa commit 3278e86
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions src/execution/__tests__/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ describe('Execute: Handles basic execution tasks', () => {
]);
});

it('uses the inline operation if no operation is provided', async () => {
it('uses the inline operation if no operation name is provided', async () => {
const doc = '{ a }';
const data = { a: 'b' };
const ast = parse(doc);
Expand All @@ -396,7 +396,7 @@ describe('Execute: Handles basic execution tasks', () => {
expect(result).to.deep.equal({ data: { a: 'b' } });
});

it('uses the only operation if no operation is provided', async () => {
it('uses the only operation if no operation name is provided', async () => {
const doc = 'query Example { a }';
const data = { a: 'b' };
const ast = parse(doc);
Expand All @@ -414,7 +414,43 @@ describe('Execute: Handles basic execution tasks', () => {
expect(result).to.deep.equal({ data: { a: 'b' } });
});

it('throws if no operation is provided with multiple operations', () => {
it('uses the named operation if operation name is provided', async () => {
const doc = 'query Example { first: a } query OtherExample { second: a }';
const data = { a: 'b' };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Type',
fields: {
a: { type: GraphQLString },
}
})
});

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

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

it('throws if no operation is provided', () => {
const doc = 'fragment Example on Type { a }';
const data = { a: 'b' };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Type',
fields: {
a: { type: GraphQLString },
}
})
});

expect(() => execute(schema, ast, data)).to.throw(
'Must provide an operation.'
);
});

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

it('throws if unknown operation name is provided', () => {
const doc = 'query Example { a } query OtherExample { a }';
const data = { a: 'b' };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Type',
fields: {
a: { type: GraphQLString },
}
})
});

expect(() => execute(schema, ast, data, null, 'UnknownExample')).to.throw(
'Unknown operation named "UnknownExample".'
);
});

it('uses the query schema for queries', async () => {
const doc = 'query Q { a } mutation M { c } subscription S { a }';
const data = { a: 'b', c: 'd' };
Expand Down

0 comments on commit 3278e86

Please sign in to comment.