diff --git a/src/execution/__tests__/subscribe-test.ts b/src/execution/__tests__/subscribe-test.ts index b1ca701185..7c18e77128 100644 --- a/src/execution/__tests__/subscribe-test.ts +++ b/src/execution/__tests__/subscribe-test.ts @@ -421,49 +421,6 @@ describe('Subscription Initialization Phase', () => { expect(() => subscribe({ schema })).to.throw('Must provide document.'); }); - it('Deprecated: allows positional arguments to createSourceEventStream', () => { - async function* fooGenerator() { - /* c8 ignore next 2 */ - yield { foo: 'FooValue' }; - } - - const schema = new GraphQLSchema({ - query: DummyQueryType, - subscription: new GraphQLObjectType({ - name: 'Subscription', - fields: { - foo: { type: GraphQLString, subscribe: fooGenerator }, - }, - }), - }); - const document = parse('subscription { foo }'); - - const eventStream = createSourceEventStream(schema, document); - assert(isAsyncIterable(eventStream)); - }); - - it('Deprecated: throws an error if document is missing when using positional arguments', async () => { - const schema = new GraphQLSchema({ - query: DummyQueryType, - subscription: new GraphQLObjectType({ - name: 'Subscription', - fields: { - foo: { type: GraphQLString }, - }, - }), - }); - - // @ts-expect-error - expect(() => createSourceEventStream(schema, null)).to.throw( - 'Must provide document.', - ); - - // @ts-expect-error - expect(() => createSourceEventStream(schema)).to.throw( - 'Must provide document.', - ); - }); - it('resolves to an error if schema does not support subscriptions', async () => { const schema = new GraphQLSchema({ query: DummyQueryType }); const document = parse('subscription { unknownField }'); diff --git a/src/execution/subscribe.ts b/src/execution/subscribe.ts index 74608d7d25..cde4fdbd6b 100644 --- a/src/execution/subscribe.ts +++ b/src/execution/subscribe.ts @@ -1,18 +1,12 @@ import { inspect } from '../jsutils/inspect'; import { isAsyncIterable } from '../jsutils/isAsyncIterable'; import { isPromise } from '../jsutils/isPromise'; -import type { Maybe } from '../jsutils/Maybe'; import { addPath, pathToArray } from '../jsutils/Path'; import type { PromiseOrValue } from '../jsutils/PromiseOrValue'; import { GraphQLError } from '../error/GraphQLError'; import { locatedError } from '../error/locatedError'; -import type { DocumentNode } from '../language/ast'; - -import type { GraphQLFieldResolver } from '../type/definition'; -import type { GraphQLSchema } from '../type/schema'; - import { collectFields } from './collectFields'; import type { ExecutionArgs, @@ -89,36 +83,6 @@ function mapSourceToResponse( ); } -type BackwardsCompatibleArgs = - | [options: ExecutionArgs] - | [ - schema: ExecutionArgs['schema'], - document: ExecutionArgs['document'], - rootValue?: ExecutionArgs['rootValue'], - contextValue?: ExecutionArgs['contextValue'], - variableValues?: ExecutionArgs['variableValues'], - operationName?: ExecutionArgs['operationName'], - subscribeFieldResolver?: ExecutionArgs['subscribeFieldResolver'], - ]; - -function toNormalizedArgs(args: BackwardsCompatibleArgs): ExecutionArgs { - const firstArg = args[0]; - if ('document' in firstArg) { - return firstArg; - } - - return { - schema: firstArg, - // FIXME: when underlying TS bug fixed, see https://github.com/microsoft/TypeScript/issues/31613 - document: args[1] as DocumentNode, - rootValue: args[2], - contextValue: args[3], - variableValues: args[4], - operationName: args[5], - subscribeFieldResolver: args[6], - }; -} - /** * Implements the "CreateSourceEventStream" algorithm described in the * GraphQL specification, resolving the subscription source event stream. @@ -149,18 +113,7 @@ function toNormalizedArgs(args: BackwardsCompatibleArgs): ExecutionArgs { */ export function createSourceEventStream( args: ExecutionArgs, -): PromiseOrValue | ExecutionResult>; -/** @deprecated will be removed in next major version in favor of named arguments */ -export function createSourceEventStream( - schema: GraphQLSchema, - document: DocumentNode, - rootValue?: unknown, - contextValue?: unknown, - variableValues?: Maybe<{ readonly [variable: string]: unknown }>, - operationName?: Maybe, - subscribeFieldResolver?: Maybe>, -): PromiseOrValue | ExecutionResult>; -export function createSourceEventStream(...rawArgs: BackwardsCompatibleArgs) { +): PromiseOrValue | ExecutionResult> { const { schema, document, @@ -169,7 +122,7 @@ export function createSourceEventStream(...rawArgs: BackwardsCompatibleArgs) { variableValues, operationName, subscribeFieldResolver, - } = toNormalizedArgs(rawArgs); + } = args; // If arguments are missing or incorrectly typed, this is an internal // developer mistake which should throw an early error.