1
1
import {
2
2
DocumentNode ,
3
- execute ,
4
- getOperationAST ,
5
3
GraphQLObjectType ,
6
4
GraphQLSchema ,
7
5
OperationTypeNode ,
@@ -35,10 +33,10 @@ import {
35
33
PubSub ,
36
34
} from '@graphql-mesh/utils' ;
37
35
import { CreateProxyingResolverFn , Subschema , SubschemaConfig } from '@graphql-tools/delegate' ;
36
+ import { normalizedExecutor } from '@graphql-tools/executor' ;
38
37
import {
39
38
ExecutionResult ,
40
39
getRootTypeMap ,
41
- inspect ,
42
40
isAsyncIterable ,
43
41
isPromise ,
44
42
mapAsyncIterator ,
@@ -76,14 +74,6 @@ const memoizedGetEnvelopedFactory = memoize1(function getEnvelopedFactory(
76
74
} ) ;
77
75
} ) ;
78
76
79
- const memoizedGetOperationType = memoize1 ( ( document : DocumentNode ) => {
80
- const operationAST = getOperationAST ( document , undefined ) ;
81
- if ( ! operationAST ) {
82
- throw new Error ( 'Must provide document with a valid operation' ) ;
83
- }
84
- return operationAST . operation ;
85
- } ) ;
86
-
87
77
export function wrapFetchWithPlugins ( plugins : MeshPlugin < any > [ ] ) : MeshFetch {
88
78
const onFetchHooks : OnFetchHook < any > [ ] = [ ] ;
89
79
for ( const plugin of plugins as MeshPlugin < any > [ ] ) {
@@ -92,24 +82,6 @@ export function wrapFetchWithPlugins(plugins: MeshPlugin<any>[]): MeshFetch {
92
82
}
93
83
}
94
84
return function wrappedFetchFn ( url , options , context , info ) {
95
- if ( url != null && typeof url !== 'string' ) {
96
- throw new TypeError ( `First parameter(url) of 'fetch' must be a string, got ${ inspect ( url ) } ` ) ;
97
- }
98
- if ( options != null && typeof options !== 'object' ) {
99
- throw new TypeError (
100
- `Second parameter(options) of 'fetch' must be an object, got ${ inspect ( options ) } ` ,
101
- ) ;
102
- }
103
- if ( context != null && typeof context !== 'object' ) {
104
- throw new TypeError (
105
- `Third parameter(context) of 'fetch' must be an object, got ${ inspect ( context ) } ` ,
106
- ) ;
107
- }
108
- if ( info != null && typeof info !== 'object' ) {
109
- throw new TypeError (
110
- `Fourth parameter(info) of 'fetch' must be an object, got ${ inspect ( info ) } ` ,
111
- ) ;
112
- }
113
85
let fetchFn : MeshFetch ;
114
86
const doneHooks : OnFetchHookDone [ ] = [ ] ;
115
87
function setFetchFn ( newFetchFn : MeshFetch ) {
@@ -318,7 +290,7 @@ export async function getMesh(options: GetMeshOptions): Promise<MeshInstance> {
318
290
319
291
const plugins = [
320
292
useEngine ( {
321
- execute,
293
+ execute : normalizedExecutor ,
322
294
validate,
323
295
parse : parseWithCache ,
324
296
specifiedRules,
@@ -368,7 +340,7 @@ export async function getMesh(options: GetMeshOptions): Promise<MeshInstance> {
368
340
369
341
function createExecutor ( globalContext : any = EMPTY_CONTEXT_VALUE ) : MeshExecutor {
370
342
const getEnveloped = memoizedGetEnvelopedFactory ( plugins ) ;
371
- const { schema, parse, execute, subscribe , contextFactory } = getEnveloped ( globalContext ) ;
343
+ const { schema, parse, execute, contextFactory } = getEnveloped ( globalContext ) ;
372
344
return function meshExecutor < TVariables = any , TContext = any , TRootValue = any , TData = any > (
373
345
documentOrSDL : GraphQLOperation < TData , TVariables > ,
374
346
variableValues : TVariables = EMPTY_VARIABLES_VALUE ,
@@ -377,11 +349,10 @@ export async function getMesh(options: GetMeshOptions): Promise<MeshInstance> {
377
349
operationName ?: string ,
378
350
) {
379
351
const document = typeof documentOrSDL === 'string' ? parse ( documentOrSDL ) : documentOrSDL ;
380
- const executeFn = memoizedGetOperationType ( document ) === 'subscription' ? subscribe : execute ;
381
352
const contextValue$ = contextFactory ( contextValue ) ;
382
353
if ( isPromise ( contextValue$ ) ) {
383
354
return contextValue$ . then ( contextValue =>
384
- executeFn ( {
355
+ execute ( {
385
356
schema,
386
357
document,
387
358
contextValue,
@@ -391,7 +362,7 @@ export async function getMesh(options: GetMeshOptions): Promise<MeshInstance> {
391
362
} ) ,
392
363
) ;
393
364
}
394
- return executeFn ( {
365
+ return execute ( {
395
366
schema,
396
367
document,
397
368
contextValue : contextValue$ ,
0 commit comments