Skip to content

Commit

Permalink
introduce executeSubscriptionEvent
Browse files Browse the repository at this point in the history
to replace the old exported functionality from execute
  • Loading branch information
yaacovCR committed Jun 24, 2022
1 parent a9a078c commit 9fc1d93
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { GraphQLBoolean, GraphQLInt, GraphQLString } from '../../type/scalars';
import { GraphQLSchema } from '../../type/schema';

import { execute, executeSync } from '../execute';
import { execute, executeSubscriptionEvent, executeSync } from '../execute';

describe('Execute: Handles basic execution tasks', () => {
it('executes arbitrary code', async () => {
Expand Down Expand Up @@ -915,6 +915,19 @@ describe('Execute: Handles basic execution tasks', () => {
},
],
});

expectJSON(
executeSubscriptionEvent({ schema, document, operationName: 'S' }),
).toDeepEqual({
data: null,
errors: [
{
message:
'Schema is not configured to execute subscription operation.',
locations: [{ line: 4, column: 7 }],
},
],
});
});

it('correct field ordering despite execution order', async () => {
Expand Down
10 changes: 10 additions & 0 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,16 @@ export function createSourceEventStream(
return prepareContextAndRunFn(args, createSourceEventStreamImpl);
}

/**
* Implements the "ExecuteSubscriptionEvent" algorithm described in the
* GraphQL specification.
*/
export function executeSubscriptionEvent(
args: ExecutionArgs,
): PromiseOrValue<ExecutionResult> {
return prepareContextAndRunFn(args, executeQuery);
}

function createSourceEventStreamImpl(
exeContext: ExecutionContext,
): PromiseOrValue<AsyncIterable<unknown> | ExecutionResult> {
Expand Down
1 change: 1 addition & 0 deletions src/execution/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { pathToArray as responsePathAsArray } from '../jsutils/Path';
export {
createSourceEventStream,
execute,
executeSubscriptionEvent,
executeSync,
defaultFieldResolver,
defaultTypeResolver,
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ export {
getDirectiveValues,
subscribe,
createSourceEventStream,
executeSubscriptionEvent,
} from './execution/index';

export type {
Expand Down
1 change: 1 addition & 0 deletions src/type/__tests__/enumType-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const SubscriptionType = new GraphQLObjectType({
async *subscribe(_source, { color }) {
yield { subscribeToEnum: color }; /* c8 ignore start */
} /* c8 ignore stop */,
resolve: (_source, { color }) => color,
},
},
});
Expand Down

0 comments on commit 9fc1d93

Please sign in to comment.