Skip to content

Commit 217ac60

Browse files
committed
Make 'defaultResolveType' to match GraphQLTypeResolver type.
1 parent f2070c8 commit 217ac60

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
@@ -43,6 +43,7 @@ import type {
4343
GraphQLField,
4444
GraphQLFieldResolver,
4545
GraphQLResolveInfo,
46+
GraphQLTypeResolver,
4647
ResponsePath,
4748
GraphQLList,
4849
} 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 =>
@@ -1172,12 +1173,12 @@ function _collectSubfields(
11721173
* Otherwise, test each possible type for the abstract type by calling
11731174
* isTypeOf for the object being coerced, returning the first type that matches.
11741175
*/
1175-
function defaultResolveTypeFn(
1176-
value: mixed,
1177-
contextValue: mixed,
1178-
info: GraphQLResolveInfo,
1179-
abstractType: GraphQLAbstractType,
1180-
): MaybePromise<?GraphQLObjectType | string> {
1176+
const defaultResolveType: GraphQLTypeResolver<any, *> = function(
1177+
value,
1178+
contextValue,
1179+
info,
1180+
abstractType,
1181+
) {
11811182
// First, look for `__typename`.
11821183
if (
11831184
value !== null &&
@@ -1214,7 +1215,7 @@ function defaultResolveTypeFn(
12141215
}
12151216
});
12161217
}
1217-
}
1218+
};
12181219

12191220
/**
12201221
* 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
@@ -779,6 +779,7 @@ export type GraphQLTypeResolver<TSource, TContext> = (
779779
value: TSource,
780780
context: TContext,
781781
info: GraphQLResolveInfo,
782+
abstractType: GraphQLAbstractType,
782783
) => MaybePromise<?GraphQLObjectType | string>;
783784

784785
export type GraphQLIsTypeOfFn<TSource, TContext> = (

0 commit comments

Comments
 (0)