Skip to content

Commit 9fc1d93

Browse files
committed
introduce executeSubscriptionEvent
to replace the old exported functionality from execute
1 parent a9a078c commit 9fc1d93

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

src/execution/__tests__/executor-test.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import { GraphQLBoolean, GraphQLInt, GraphQLString } from '../../type/scalars';
2121
import { GraphQLSchema } from '../../type/schema';
2222

23-
import { execute, executeSync } from '../execute';
23+
import { execute, executeSubscriptionEvent, executeSync } from '../execute';
2424

2525
describe('Execute: Handles basic execution tasks', () => {
2626
it('executes arbitrary code', async () => {
@@ -915,6 +915,19 @@ describe('Execute: Handles basic execution tasks', () => {
915915
},
916916
],
917917
});
918+
919+
expectJSON(
920+
executeSubscriptionEvent({ schema, document, operationName: 'S' }),
921+
).toDeepEqual({
922+
data: null,
923+
errors: [
924+
{
925+
message:
926+
'Schema is not configured to execute subscription operation.',
927+
locations: [{ line: 4, column: 7 }],
928+
},
929+
],
930+
});
918931
});
919932

920933
it('correct field ordering despite execution order', async () => {

src/execution/execute.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,16 @@ export function createSourceEventStream(
12211221
return prepareContextAndRunFn(args, createSourceEventStreamImpl);
12221222
}
12231223

1224+
/**
1225+
* Implements the "ExecuteSubscriptionEvent" algorithm described in the
1226+
* GraphQL specification.
1227+
*/
1228+
export function executeSubscriptionEvent(
1229+
args: ExecutionArgs,
1230+
): PromiseOrValue<ExecutionResult> {
1231+
return prepareContextAndRunFn(args, executeQuery);
1232+
}
1233+
12241234
function createSourceEventStreamImpl(
12251235
exeContext: ExecutionContext,
12261236
): PromiseOrValue<AsyncIterable<unknown> | ExecutionResult> {

src/execution/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export { pathToArray as responsePathAsArray } from '../jsutils/Path';
33
export {
44
createSourceEventStream,
55
execute,
6+
executeSubscriptionEvent,
67
executeSync,
78
defaultFieldResolver,
89
defaultTypeResolver,

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ export {
321321
getDirectiveValues,
322322
subscribe,
323323
createSourceEventStream,
324+
executeSubscriptionEvent,
324325
} from './execution/index';
325326

326327
export type {

src/type/__tests__/enumType-test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const SubscriptionType = new GraphQLObjectType({
110110
async *subscribe(_source, { color }) {
111111
yield { subscribeToEnum: color }; /* c8 ignore start */
112112
} /* c8 ignore stop */,
113+
resolve: (_source, { color }) => color,
113114
},
114115
},
115116
});

0 commit comments

Comments
 (0)