1
- import { isObjectLike } from '../jsutils/isObjectLike' ;
2
- import { isPromise } from '../jsutils/isPromise' ;
3
1
import type { ObjMap } from '../jsutils/ObjMap' ;
4
2
5
3
import { GraphQLError } from '../error/GraphQLError' ;
@@ -10,11 +8,6 @@ import type {
10
8
} from '../language/ast' ;
11
9
import { Kind } from '../language/kinds' ;
12
10
13
- import type {
14
- GraphQLFieldResolver ,
15
- GraphQLTypeResolver ,
16
- } from '../type/definition' ;
17
- import type { GraphQLSchema } from '../type/schema' ;
18
11
import { assertValidSchema } from '../type/validate' ;
19
12
20
13
import type { ExecutionArgs } from './execute' ;
@@ -27,15 +20,11 @@ import { getVariableValues } from './values';
27
20
* and the fragments defined in the query document
28
21
*/
29
22
export interface ExecutionContext {
30
- schema : GraphQLSchema ;
31
23
fragments : ObjMap < FragmentDefinitionNode > ;
32
24
rootValue : unknown ;
33
25
contextValue : unknown ;
34
26
operation : OperationDefinitionNode ;
35
27
variableValues : { [ variable : string ] : unknown } ;
36
- fieldResolver : GraphQLFieldResolver < any , any > ;
37
- typeResolver : GraphQLTypeResolver < any , any > ;
38
- subscribeFieldResolver : GraphQLFieldResolver < any , any > ;
39
28
errors : Array < GraphQLError > ;
40
29
}
41
30
@@ -58,9 +47,6 @@ export function buildExecutionContext(
58
47
contextValue,
59
48
variableValues : rawVariableValues ,
60
49
operationName,
61
- fieldResolver,
62
- typeResolver,
63
- subscribeFieldResolver,
64
50
} = args ;
65
51
66
52
// If the schema used for execution is invalid, throw an error.
@@ -115,15 +101,11 @@ export function buildExecutionContext(
115
101
}
116
102
117
103
return {
118
- schema,
119
104
fragments,
120
105
rootValue,
121
106
contextValue,
122
107
operation,
123
108
variableValues : coercedVariableValues . coerced ,
124
- fieldResolver : fieldResolver ?? defaultFieldResolver ,
125
- typeResolver : typeResolver ?? defaultTypeResolver ,
126
- subscribeFieldResolver : subscribeFieldResolver ?? defaultFieldResolver ,
127
109
errors : [ ] ,
128
110
} ;
129
111
}
@@ -141,67 +123,3 @@ export function buildPerEventExecutionContext(
141
123
errors : [ ] ,
142
124
} ;
143
125
}
144
-
145
- /**
146
- * If a resolveType function is not given, then a default resolve behavior is
147
- * used which attempts two strategies:
148
- *
149
- * First, See if the provided value has a `__typename` field defined, if so, use
150
- * that value as name of the resolved type.
151
- *
152
- * Otherwise, test each possible type for the abstract type by calling
153
- * isTypeOf for the object being coerced, returning the first type that matches.
154
- */
155
- export const defaultTypeResolver : GraphQLTypeResolver < unknown , unknown > =
156
- function ( value , contextValue , info , abstractType ) {
157
- // First, look for `__typename`.
158
- if ( isObjectLike ( value ) && typeof value . __typename === 'string' ) {
159
- return value . __typename ;
160
- }
161
-
162
- // Otherwise, test each possible type.
163
- const possibleTypes = info . schema . getPossibleTypes ( abstractType ) ;
164
- const promisedIsTypeOfResults = [ ] ;
165
-
166
- for ( let i = 0 ; i < possibleTypes . length ; i ++ ) {
167
- const type = possibleTypes [ i ] ;
168
-
169
- if ( type . isTypeOf ) {
170
- const isTypeOfResult = type . isTypeOf ( value , contextValue , info ) ;
171
-
172
- if ( isPromise ( isTypeOfResult ) ) {
173
- promisedIsTypeOfResults [ i ] = isTypeOfResult ;
174
- } else if ( isTypeOfResult ) {
175
- return type . name ;
176
- }
177
- }
178
- }
179
-
180
- if ( promisedIsTypeOfResults . length ) {
181
- return Promise . all ( promisedIsTypeOfResults ) . then ( ( isTypeOfResults ) => {
182
- for ( let i = 0 ; i < isTypeOfResults . length ; i ++ ) {
183
- if ( isTypeOfResults [ i ] ) {
184
- return possibleTypes [ i ] . name ;
185
- }
186
- }
187
- } ) ;
188
- }
189
- } ;
190
-
191
- /**
192
- * If a resolve function is not given, then a default resolve behavior is used
193
- * which takes the property of the source object of the same name as the field
194
- * and returns it as the result, or if it's a function, returns the result
195
- * of calling that function while passing along args and context value.
196
- */
197
- export const defaultFieldResolver : GraphQLFieldResolver < unknown , unknown > =
198
- function ( source : any , args , contextValue , info ) {
199
- // ensure source is a value for which property access is acceptable.
200
- if ( isObjectLike ( source ) || typeof source === 'function' ) {
201
- const property = source [ info . fieldName ] ;
202
- if ( typeof property === 'function' ) {
203
- return source [ info . fieldName ] ( args , contextValue , info ) ;
204
- }
205
- return property ;
206
- }
207
- } ;
0 commit comments