1- import { isObjectLike } from '../jsutils/isObjectLike' ;
2- import { isPromise } from '../jsutils/isPromise' ;
31import type { ObjMap } from '../jsutils/ObjMap' ;
42
53import { GraphQLError } from '../error/GraphQLError' ;
@@ -10,11 +8,6 @@ import type {
108} from '../language/ast' ;
119import { Kind } from '../language/kinds' ;
1210
13- import type {
14- GraphQLFieldResolver ,
15- GraphQLTypeResolver ,
16- } from '../type/definition' ;
17- import type { GraphQLSchema } from '../type/schema' ;
1811import { assertValidSchema } from '../type/validate' ;
1912
2013import type { ExecutionArgs } from './execute' ;
@@ -27,15 +20,11 @@ import { getVariableValues } from './values';
2720 * and the fragments defined in the query document
2821 */
2922export interface ExecutionContext {
30- schema : GraphQLSchema ;
3123 fragments : ObjMap < FragmentDefinitionNode > ;
3224 rootValue : unknown ;
3325 contextValue : unknown ;
3426 operation : OperationDefinitionNode ;
3527 variableValues : { [ variable : string ] : unknown } ;
36- fieldResolver : GraphQLFieldResolver < any , any > ;
37- typeResolver : GraphQLTypeResolver < any , any > ;
38- subscribeFieldResolver : GraphQLFieldResolver < any , any > ;
3928 errors : Array < GraphQLError > ;
4029}
4130
@@ -58,9 +47,6 @@ export function buildExecutionContext(
5847 contextValue,
5948 variableValues : rawVariableValues ,
6049 operationName,
61- fieldResolver,
62- typeResolver,
63- subscribeFieldResolver,
6450 } = args ;
6551
6652 // If the schema used for execution is invalid, throw an error.
@@ -115,15 +101,11 @@ export function buildExecutionContext(
115101 }
116102
117103 return {
118- schema,
119104 fragments,
120105 rootValue,
121106 contextValue,
122107 operation,
123108 variableValues : coercedVariableValues . coerced ,
124- fieldResolver : fieldResolver ?? defaultFieldResolver ,
125- typeResolver : typeResolver ?? defaultTypeResolver ,
126- subscribeFieldResolver : subscribeFieldResolver ?? defaultFieldResolver ,
127109 errors : [ ] ,
128110 } ;
129111}
@@ -141,67 +123,3 @@ export function buildPerEventExecutionContext(
141123 errors : [ ] ,
142124 } ;
143125}
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