Skip to content

Commit a2c982f

Browse files
authored
createSourceEventStream: remove deprecated positional arguments (#3635)
1 parent db643e9 commit a2c982f

File tree

2 files changed

+2
-92
lines changed

2 files changed

+2
-92
lines changed

src/execution/__tests__/subscribe-test.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -421,49 +421,6 @@ describe('Subscription Initialization Phase', () => {
421421
expect(() => subscribe({ schema })).to.throw('Must provide document.');
422422
});
423423

424-
it('Deprecated: allows positional arguments to createSourceEventStream', () => {
425-
async function* fooGenerator() {
426-
/* c8 ignore next 2 */
427-
yield { foo: 'FooValue' };
428-
}
429-
430-
const schema = new GraphQLSchema({
431-
query: DummyQueryType,
432-
subscription: new GraphQLObjectType({
433-
name: 'Subscription',
434-
fields: {
435-
foo: { type: GraphQLString, subscribe: fooGenerator },
436-
},
437-
}),
438-
});
439-
const document = parse('subscription { foo }');
440-
441-
const eventStream = createSourceEventStream(schema, document);
442-
assert(isAsyncIterable(eventStream));
443-
});
444-
445-
it('Deprecated: throws an error if document is missing when using positional arguments', async () => {
446-
const schema = new GraphQLSchema({
447-
query: DummyQueryType,
448-
subscription: new GraphQLObjectType({
449-
name: 'Subscription',
450-
fields: {
451-
foo: { type: GraphQLString },
452-
},
453-
}),
454-
});
455-
456-
// @ts-expect-error
457-
expect(() => createSourceEventStream(schema, null)).to.throw(
458-
'Must provide document.',
459-
);
460-
461-
// @ts-expect-error
462-
expect(() => createSourceEventStream(schema)).to.throw(
463-
'Must provide document.',
464-
);
465-
});
466-
467424
it('resolves to an error if schema does not support subscriptions', async () => {
468425
const schema = new GraphQLSchema({ query: DummyQueryType });
469426
const document = parse('subscription { unknownField }');

src/execution/subscribe.ts

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import { inspect } from '../jsutils/inspect';
22
import { isAsyncIterable } from '../jsutils/isAsyncIterable';
33
import { isPromise } from '../jsutils/isPromise';
4-
import type { Maybe } from '../jsutils/Maybe';
54
import { addPath, pathToArray } from '../jsutils/Path';
65
import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
76

87
import { GraphQLError } from '../error/GraphQLError';
98
import { locatedError } from '../error/locatedError';
109

11-
import type { DocumentNode } from '../language/ast';
12-
13-
import type { GraphQLFieldResolver } from '../type/definition';
14-
import type { GraphQLSchema } from '../type/schema';
15-
1610
import { collectFields } from './collectFields';
1711
import type {
1812
ExecutionArgs,
@@ -89,36 +83,6 @@ function mapSourceToResponse(
8983
);
9084
}
9185

92-
type BackwardsCompatibleArgs =
93-
| [options: ExecutionArgs]
94-
| [
95-
schema: ExecutionArgs['schema'],
96-
document: ExecutionArgs['document'],
97-
rootValue?: ExecutionArgs['rootValue'],
98-
contextValue?: ExecutionArgs['contextValue'],
99-
variableValues?: ExecutionArgs['variableValues'],
100-
operationName?: ExecutionArgs['operationName'],
101-
subscribeFieldResolver?: ExecutionArgs['subscribeFieldResolver'],
102-
];
103-
104-
function toNormalizedArgs(args: BackwardsCompatibleArgs): ExecutionArgs {
105-
const firstArg = args[0];
106-
if ('document' in firstArg) {
107-
return firstArg;
108-
}
109-
110-
return {
111-
schema: firstArg,
112-
// FIXME: when underlying TS bug fixed, see https://github.com/microsoft/TypeScript/issues/31613
113-
document: args[1] as DocumentNode,
114-
rootValue: args[2],
115-
contextValue: args[3],
116-
variableValues: args[4],
117-
operationName: args[5],
118-
subscribeFieldResolver: args[6],
119-
};
120-
}
121-
12286
/**
12387
* Implements the "CreateSourceEventStream" algorithm described in the
12488
* GraphQL specification, resolving the subscription source event stream.
@@ -149,18 +113,7 @@ function toNormalizedArgs(args: BackwardsCompatibleArgs): ExecutionArgs {
149113
*/
150114
export function createSourceEventStream(
151115
args: ExecutionArgs,
152-
): PromiseOrValue<AsyncIterable<unknown> | ExecutionResult>;
153-
/** @deprecated will be removed in next major version in favor of named arguments */
154-
export function createSourceEventStream(
155-
schema: GraphQLSchema,
156-
document: DocumentNode,
157-
rootValue?: unknown,
158-
contextValue?: unknown,
159-
variableValues?: Maybe<{ readonly [variable: string]: unknown }>,
160-
operationName?: Maybe<string>,
161-
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
162-
): PromiseOrValue<AsyncIterable<unknown> | ExecutionResult>;
163-
export function createSourceEventStream(...rawArgs: BackwardsCompatibleArgs) {
116+
): PromiseOrValue<AsyncIterable<unknown> | ExecutionResult> {
164117
const {
165118
schema,
166119
document,
@@ -169,7 +122,7 @@ export function createSourceEventStream(...rawArgs: BackwardsCompatibleArgs) {
169122
variableValues,
170123
operationName,
171124
subscribeFieldResolver,
172-
} = toNormalizedArgs(rawArgs);
125+
} = args;
173126

174127
// If arguments are missing or incorrectly typed, this is an internal
175128
// developer mistake which should throw an early error.

0 commit comments

Comments
 (0)