Skip to content

Commit ab12f8a

Browse files
committed
introduce executeSubscriptionEvent
to replace the old exported functionality from execute
1 parent eaf786d commit ab12f8a

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

src/execution/__tests__/executor-test.ts

Lines changed: 14 additions & 1 deletion
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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,18 @@ export function createSourceEventStream(
11391139
return prepareContextAndRunFn(args, createSourceEventStreamImpl);
11401140
}
11411141

1142+
/**
1143+
* Implements the "ExecuteSubscriptionEvent" algorithm described in the
1144+
* GraphQL specification.
1145+
*/
1146+
export function executeSubscriptionEvent(
1147+
args: ExecutionArgs,
1148+
): PromiseOrValue<ExecutionResult> {
1149+
return prepareContextAndRunFn(args, (exeContext) =>
1150+
executeQueryOrMutation(exeContext, executeFields),
1151+
);
1152+
}
1153+
11421154
function createSourceEventStreamImpl(
11431155
exeContext: ExecutionContext,
11441156
): PromiseOrValue<AsyncIterable<unknown> | ExecutionResult> {

src/execution/index.ts

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)