Skip to content
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

refactor: execution methods into Executor class #3185

Merged
merged 20 commits into from Jun 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/README.md
Expand Up @@ -20,4 +20,3 @@ Each sub directory within is a sub-module of graphql-js:
- [`graphql/error`](error/README.md): Creating and formatting GraphQL errors.
- [`graphql/utilities`](utilities/README.md): Common useful computations upon
the GraphQL language and type objects.
- [`graphql/subscription`](subscription/README.md): Subscribe to data updates.
23 changes: 23 additions & 0 deletions src/error/GraphQLAggregateError.ts
@@ -0,0 +1,23 @@
import type { GraphQLError } from './GraphQLError';

/**
* A GraphQLAggregateError contains a collection of GraphQLError objects.
* See documentation for the GraphQLError class for further details.
*
* @internal
*
* TODO: Consider exposing this class for returning multiple errors from
* resolvers.
*/
export class GraphQLAggregateError extends Error {
/**
* An array of GraphQLError objects.
*
*/
readonly errors: ReadonlyArray<GraphQLError>;

constructor(errors: ReadonlyArray<GraphQLError>) {
super();
this.errors = errors;
}
}
Expand Up @@ -6,13 +6,14 @@ import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick';
import { invariant } from '../../jsutils/invariant';
import { isAsyncIterable } from '../../jsutils/isAsyncIterable';

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

import { GraphQLSchema } from '../../type/schema';
import { GraphQLList, GraphQLObjectType } from '../../type/definition';
import { GraphQLInt, GraphQLString, GraphQLBoolean } from '../../type/scalars';

import { createSourceEventStream, subscribe } from '../subscribe';
import { subscribe } from '../subscribe';

import { SimplePubSub } from './simplePubSub';

Expand Down Expand Up @@ -406,10 +407,6 @@ describe('Subscription Initialization Phase', () => {
});
const document = parse('subscription { foo }');
const result = await subscribe({ schema, document });

expect(await createSourceEventStream(schema, document)).to.deep.equal(
result,
);
return result;
}

Expand Down Expand Up @@ -446,6 +443,32 @@ describe('Subscription Initialization Phase', () => {
).to.deep.equal(expectedResult);
});

it('resolves to an error if no operation is provided', async () => {
const schema = new GraphQLSchema({
query: DummyQueryType,
subscription: new GraphQLObjectType({
name: 'Subscription',
fields: {
foo: { type: GraphQLString },
},
}),
});

// If we receive variables that cannot be coerced correctly, subscribe() will
// resolve to an ExecutionResult that contains an informative error description.
const result = await subscribe({
schema,
document: { kind: Kind.DOCUMENT, definitions: [] },
});
expect(result).to.deep.equal({
errors: [
{
message: 'Must provide an operation.',
},
],
});
});

it('resolves to an error if variables were wrong type', async () => {
const schema = new GraphQLSchema({
query: DummyQueryType,
Expand Down