Skip to content

Commit d757a59

Browse files
committed
createSourceEventStream: remove deprecated positional arguments (graphql#3635)
1 parent fdfa381 commit d757a59

File tree

2 files changed

+1
-109
lines changed

2 files changed

+1
-109
lines changed

src/execution/__tests__/subscribe-test.ts

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function subscribeWithBadFn(
191191

192192
return expectEqualPromisesOrValues(
193193
subscribe({ schema, document }),
194-
createSourceEventStream(schema, document),
194+
createSourceEventStream({ schema, document }),
195195
);
196196
}
197197

@@ -421,63 +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', async () => {
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 = await 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 document = parse('subscription { foo }');
447-
const schema = new GraphQLSchema({
448-
query: DummyQueryType,
449-
subscription: new GraphQLObjectType({
450-
name: 'Subscription',
451-
fields: {
452-
foo: { type: GraphQLString },
453-
},
454-
}),
455-
});
456-
457-
// @ts-expect-error (schema must not be null)
458-
expect(() => createSourceEventStream(null, document)).to.throw(
459-
'Expected null to be a GraphQL schema.',
460-
);
461-
462-
expect(() =>
463-
createSourceEventStream(
464-
// @ts-expect-error
465-
undefined,
466-
document,
467-
),
468-
).to.throw('Expected undefined to be a GraphQL schema.');
469-
470-
// @ts-expect-error (document must not be null)
471-
expect(() => createSourceEventStream(schema, null)).to.throw(
472-
'Must provide document.',
473-
);
474-
475-
// @ts-expect-error
476-
expect(() => createSourceEventStream(schema)).to.throw(
477-
'Must provide document.',
478-
);
479-
});
480-
481424
it('resolves to an error if schema does not support subscriptions', async () => {
482425
const schema = new GraphQLSchema({ query: DummyQueryType });
483426
const document = parse('subscription { unknownField }');

src/execution/subscribe.ts

Lines changed: 0 additions & 51 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 (firstArg && '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,22 +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(
164-
...rawArgs: BackwardsCompatibleArgs
165116
): PromiseOrValue<AsyncIterable<unknown> | ExecutionResult> {
166-
const args = toNormalizedArgs(rawArgs);
167-
168117
const { schema, document, variableValues } = args;
169118

170119
// If arguments are missing or incorrectly typed, this is an internal

0 commit comments

Comments
 (0)