Skip to content

Commit 8f7e484

Browse files
committed
Make 'defaultResolveType' to match GraphQLTypeResolver type.
1 parent 2eccaad commit 8f7e484

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/execution/execute.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import type {
4040
GraphQLAbstractType,
4141
GraphQLField,
4242
GraphQLFieldResolver,
43+
GraphQLTypeResolver,
4344
GraphQLResolveInfo,
4445
ResponsePath,
4546
GraphQLList,
@@ -1027,9 +1028,10 @@ function completeAbstractValue(
10271028
path: ResponsePath,
10281029
result: mixed,
10291030
): MaybePromise<ObjMap<mixed>> {
1030-
const runtimeType = returnType.resolveType
1031-
? returnType.resolveType(result, exeContext.contextValue, info)
1032-
: defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
1031+
const resolveTypeFn = returnType.resolveType || defaultResolveType;
1032+
const contextValue = exeContext.contextValue;
1033+
const typeInfo = { ...info, valueType: returnType, valuePath: path };
1034+
const runtimeType = resolveTypeFn(result, contextValue, typeInfo);
10331035

10341036
if (isPromise(runtimeType)) {
10351037
return runtimeType.then(resolvedRuntimeType =>
@@ -1211,12 +1213,11 @@ function _collectSubfields(
12111213
* Otherwise, test each possible type for the abstract type by calling
12121214
* isTypeOf for the object being coerced, returning the first type that matches.
12131215
*/
1214-
function defaultResolveTypeFn(
1215-
value: mixed,
1216-
contextValue: mixed,
1217-
info: GraphQLResolveInfo,
1218-
abstractType: GraphQLAbstractType,
1219-
): MaybePromise<?GraphQLObjectType | string> {
1216+
const defaultResolveType: GraphQLTypeResolver<any, *> = function(
1217+
value,
1218+
contextValue,
1219+
info,
1220+
) {
12201221
// First, look for `__typename`.
12211222
if (
12221223
value !== null &&
@@ -1227,7 +1228,7 @@ function defaultResolveTypeFn(
12271228
}
12281229

12291230
// Otherwise, test each possible type.
1230-
const possibleTypes = info.schema.getPossibleTypes(abstractType);
1231+
const possibleTypes = info.schema.getPossibleTypes(info.valueType);
12311232
const promisedIsTypeOfResults = [];
12321233

12331234
for (let i = 0; i < possibleTypes.length; i++) {
@@ -1253,7 +1254,7 @@ function defaultResolveTypeFn(
12531254
}
12541255
});
12551256
}
1256-
}
1257+
};
12571258

12581259
/**
12591260
* If a resolve function is not given, then a default resolve behavior is used

src/type/definition.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ export type GraphQLObjectTypeConfig<TSource, TContext> = {
785785
export type GraphQLTypeResolver<TSource, TContext> = (
786786
value: TSource,
787787
context: TContext,
788-
info: GraphQLResolveInfo,
788+
info: GraphQLTypeResolveInfo,
789789
) => MaybePromise<?GraphQLObjectType | string>;
790790

791791
export type GraphQLIsTypeOfFn<TSource, TContext> = (
@@ -805,7 +805,7 @@ export type GraphQLFieldResolver<
805805
info: GraphQLResolveInfo,
806806
) => mixed;
807807

808-
export type GraphQLResolveInfo = {|
808+
export type GraphQLResolveInfo = {
809809
+fieldName: string,
810810
+fieldNodes: $ReadOnlyArray<FieldNode>,
811811
+returnType: GraphQLOutputType,
@@ -816,6 +816,12 @@ export type GraphQLResolveInfo = {|
816816
+rootValue: mixed,
817817
+operation: OperationDefinitionNode,
818818
+variableValues: { [variable: string]: mixed },
819+
};
820+
821+
export type GraphQLTypeResolveInfo = {|
822+
...GraphQLTypeResolveInfo,
823+
+valueType: GraphQLAbstractType,
824+
+valuePath: ResponsePath,
819825
|};
820826

821827
export type ResponsePath = {|

0 commit comments

Comments
 (0)