Skip to content

Commit 3cbefb8

Browse files
committed
Make 'defaultResolveType' to match GraphQLTypeResolver type.
1 parent 94b3844 commit 3cbefb8

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';
@@ -988,9 +989,9 @@ function completeAbstractValue(
988989
path: ResponsePath,
989990
result: mixed,
990991
): MaybePromise<ObjMap<mixed>> {
991-
const runtimeType = returnType.resolveType
992-
? returnType.resolveType(result, exeContext.contextValue, info)
993-
: defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
992+
const resolveTypeFn = returnType.resolveType || defaultResolveType;
993+
const contextValue = exeContext.contextValue;
994+
const runtimeType = resolveTypeFn(result, contextValue, info, returnType);
994995

995996
if (isPromise(runtimeType)) {
996997
return runtimeType.then(resolvedRuntimeType =>
@@ -1171,12 +1172,12 @@ function _collectSubfields(
11711172
* Otherwise, test each possible type for the abstract type by calling
11721173
* isTypeOf for the object being coerced, returning the first type that matches.
11731174
*/
1174-
function defaultResolveTypeFn(
1175-
value: mixed,
1176-
contextValue: mixed,
1177-
info: GraphQLResolveInfo,
1178-
abstractType: GraphQLAbstractType,
1179-
): MaybePromise<?GraphQLObjectType | string> {
1175+
const defaultResolveType: GraphQLTypeResolver<any, *> = function(
1176+
value,
1177+
contextValue,
1178+
info,
1179+
abstractType,
1180+
) {
11801181
// First, look for `__typename`.
11811182
if (
11821183
value !== null &&
@@ -1213,7 +1214,7 @@ function defaultResolveTypeFn(
12131214
}
12141215
});
12151216
}
1216-
}
1217+
};
12171218

12181219
/**
12191220
* 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
@@ -770,6 +770,7 @@ export type GraphQLTypeResolver<TSource, TContext> = (
770770
value: TSource,
771771
context: TContext,
772772
info: GraphQLResolveInfo,
773+
abstractType: GraphQLAbstractType,
773774
) => MaybePromise<?GraphQLObjectType | string>;
774775
775776
export type GraphQLIsTypeOfFn<TSource, TContext> = (

0 commit comments

Comments
 (0)