@@ -13,7 +13,6 @@ import type { DocumentNode } from '../language/ast';
13
13
14
14
import type { GraphQLFieldResolver } from '../type/definition' ;
15
15
import type { GraphQLSchema } from '../type/schema' ;
16
- import { isSchema } from '../type/schema' ;
17
16
18
17
import { collectFields } from './collectFields' ;
19
18
import type {
@@ -91,6 +90,37 @@ function mapSourceToResponse(
91
90
) ;
92
91
}
93
92
93
+ type BackwardsCompatibleArgs =
94
+ | [ options : ExecutionArgs ]
95
+ | [
96
+ schema : ExecutionArgs [ 'schema' ] ,
97
+ document : ExecutionArgs [ 'document' ] ,
98
+ rootValue ?: ExecutionArgs [ 'rootValue' ] ,
99
+ contextValue ?: ExecutionArgs [ 'contextValue' ] ,
100
+ variableValues ?: ExecutionArgs [ 'variableValues' ] ,
101
+ operationName ?: ExecutionArgs [ 'operationName' ] ,
102
+ subscribeFieldResolver ?: ExecutionArgs [ 'subscribeFieldResolver' ] ,
103
+ ] ;
104
+
105
+ function toNormalizedArgs ( args : BackwardsCompatibleArgs ) : ExecutionArgs {
106
+ const firstArg = args [ 0 ] ;
107
+ if ( 'document' in firstArg ) {
108
+ return firstArg ;
109
+ }
110
+
111
+ invariant ( args [ 1 ] != null , 'Must provide document.' ) ;
112
+
113
+ return {
114
+ schema : firstArg ,
115
+ document : args [ 1 ] ,
116
+ rootValue : args [ 2 ] ,
117
+ contextValue : args [ 3 ] ,
118
+ variableValues : args [ 4 ] ,
119
+ operationName : args [ 5 ] ,
120
+ subscribeFieldResolver : args [ 6 ] ,
121
+ } ;
122
+ }
123
+
94
124
/**
95
125
* Implements the "CreateSourceEventStream" algorithm described in the
96
126
* GraphQL specification, resolving the subscription source event stream.
@@ -132,34 +162,7 @@ export function createSourceEventStream(
132
162
operationName ?: Maybe < string > ,
133
163
subscribeFieldResolver ?: Maybe < GraphQLFieldResolver < any , any > > ,
134
164
) : PromiseOrValue < AsyncIterable < unknown > | ExecutionResult > ;
135
- export function createSourceEventStream (
136
- argsOrSchema : ExecutionArgs | GraphQLSchema ,
137
- document ?: DocumentNode ,
138
- rootValue ?: unknown ,
139
- contextValue ?: unknown ,
140
- variableValues ?: Maybe < { readonly [ variable : string ] : unknown } > ,
141
- operationName ?: Maybe < string > ,
142
- subscribeFieldResolver ?: Maybe < GraphQLFieldResolver < any , any > > ,
143
- ) : PromiseOrValue < AsyncIterable < unknown > | ExecutionResult > {
144
- if ( isSchema ( argsOrSchema ) ) {
145
- invariant ( document != null , 'Must provide document.' ) ;
146
- return createSourceEventStreamImpl ( {
147
- schema : argsOrSchema ,
148
- document,
149
- rootValue,
150
- contextValue,
151
- variableValues,
152
- operationName,
153
- subscribeFieldResolver,
154
- } ) ;
155
- }
156
-
157
- return createSourceEventStreamImpl ( argsOrSchema ) ;
158
- }
159
-
160
- export function createSourceEventStreamImpl (
161
- args : ExecutionArgs ,
162
- ) : PromiseOrValue < AsyncIterable < unknown > | ExecutionResult > {
165
+ export function createSourceEventStream ( ...rawArgs : BackwardsCompatibleArgs ) {
163
166
const {
164
167
schema,
165
168
document,
@@ -168,7 +171,7 @@ export function createSourceEventStreamImpl(
168
171
variableValues,
169
172
operationName,
170
173
subscribeFieldResolver,
171
- } = args ;
174
+ } = toNormalizedArgs ( rawArgs ) ;
172
175
173
176
// If arguments are missing or incorrectly typed, this is an internal
174
177
// developer mistake which should throw an early error.
0 commit comments