Skip to content

Commit 898cf20

Browse files
committed
Make 'defaultResolveType' to match GraphQLTypeResolver type.
1 parent 92e647c commit 898cf20

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/execution/execute.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import type {
4444
GraphQLField,
4545
GraphQLFieldResolver,
4646
GraphQLResolveInfo,
47+
GraphQLTypeResolver,
4748
ResponsePath,
4849
GraphQLList,
4950
} from '../type/definition';
@@ -991,9 +992,9 @@ function completeAbstractValue(
991992
path: ResponsePath,
992993
result: mixed,
993994
): MaybePromise<ObjMap<mixed>> {
994-
const runtimeType = returnType.resolveType
995-
? returnType.resolveType(result, exeContext.contextValue, info)
996-
: defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
995+
const resolveTypeFn = returnType.resolveType || defaultResolveType;
996+
const contextValue = exeContext.contextValue;
997+
const runtimeType = resolveTypeFn(result, contextValue, info, returnType);
997998

998999
if (isPromise(runtimeType)) {
9991000
return runtimeType.then(resolvedRuntimeType =>
@@ -1174,12 +1175,12 @@ function _collectSubfields(
11741175
* Otherwise, test each possible type for the abstract type by calling
11751176
* isTypeOf for the object being coerced, returning the first type that matches.
11761177
*/
1177-
function defaultResolveTypeFn(
1178-
value: mixed,
1179-
contextValue: mixed,
1180-
info: GraphQLResolveInfo,
1181-
abstractType: GraphQLAbstractType,
1182-
): MaybePromise<?GraphQLObjectType | string> {
1178+
const defaultResolveType: GraphQLTypeResolver<any, *> = function(
1179+
value,
1180+
contextValue,
1181+
info,
1182+
abstractType,
1183+
) {
11831184
// First, look for `__typename`.
11841185
if (
11851186
value !== null &&
@@ -1216,7 +1217,7 @@ function defaultResolveTypeFn(
12161217
}
12171218
});
12181219
}
1219-
}
1220+
};
12201221

12211222
/**
12221223
* If a resolve function is not given, then a default resolve behavior is used

src/type/definition.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ export type GraphQLTypeResolver<TSource, TContext> = (
832832
value: TSource,
833833
context: TContext,
834834
info: GraphQLResolveInfo,
835+
abstractType: GraphQLAbstractType,
835836
) => MaybePromise<?GraphQLObjectType | string>;
836837

837838
export type GraphQLIsTypeOfFn<TSource, TContext> = (

0 commit comments

Comments
 (0)