Skip to content

Commit 1305360

Browse files
authored
Reduce scope
Just reverts a few unrelated parts of the change
1 parent ae5295a commit 1305360

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

src/execution/execute.js

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -941,30 +941,24 @@ function completeAbstractValue(
941941
result: mixed
942942
): mixed {
943943
const runtimeType = returnType.resolveType ?
944-
returnType.resolveType(
945-
result,
946-
exeContext.contextValue,
947-
info
948-
) :
949-
defaultResolveTypeFn(
950-
result,
951-
exeContext.contextValue,
952-
info,
953-
returnType
954-
);
944+
returnType.resolveType(result, exeContext.contextValue, info) :
945+
defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
955946

956947
if (isThenable(runtimeType)) {
957-
return ((runtimeType: any): Promise<*>).then(resolvedRuntimeType => (
948+
// Cast to Promise
949+
const runtimeTypePromise: Promise<GraphQLObjectType | string> =
950+
(runtimeType: any);
951+
return runtimeTypePromise.then(resolvedRuntimeType =>
958952
validateRuntimeTypeAndCompleteObjectValue(
959953
exeContext,
960954
returnType,
961955
fieldNodes,
962956
info,
963957
path,
964-
resolvedRuntimeType,
958+
ensureType(exeContext.schema, resolvedRuntimeType),
965959
result
966960
)
967-
));
961+
);
968962
}
969963

970964
return validateRuntimeTypeAndCompleteObjectValue(
@@ -973,27 +967,29 @@ function completeAbstractValue(
973967
fieldNodes,
974968
info,
975969
path,
976-
runtimeType,
970+
ensureType(exeContext.schema, runtimeType),
977971
result
978972
);
979973
}
980974

975+
function ensureType(
976+
schema: GraphQLSchema,
977+
typeOrName: string | GraphQLObjectType
978+
): GraphQLObjectType {
979+
return typeof typeOrName === 'string' ?
980+
schema.getType(typeOrName) :
981+
typeOrName;
982+
}
983+
981984
function validateRuntimeTypeAndCompleteObjectValue(
982985
exeContext: ExecutionContext,
983986
returnType: GraphQLAbstractType,
984987
fieldNodes: Array<FieldNode>,
985988
info: GraphQLResolveInfo,
986989
path: ResponsePath,
987-
returnedRuntimeType: mixed,
990+
runtimeType: GraphQLObjectType,
988991
result: mixed
989992
): mixed {
990-
let runtimeType = returnedRuntimeType;
991-
992-
// If resolveType returns a string, we assume it's a GraphQLObjectType name.
993-
if (typeof runtimeType === 'string') {
994-
runtimeType = exeContext.schema.getType(runtimeType);
995-
}
996-
997993
if (!(runtimeType instanceof GraphQLObjectType)) {
998994
throw new GraphQLError(
999995
`Abstract type ${returnType.name} must resolve to an Object type at ` +
@@ -1087,16 +1083,14 @@ function validateResultTypeAndExecuteFields(
10871083
// rather than continuing execution.
10881084
if (!isTypeOfResult) {
10891085
throw new GraphQLError(
1090-
`Expected value of type "${returnType.name}" ` +
1091-
`but got: ${String(result)}.`,
1086+
`Expected value of type "${returnType.name}" but got: ${String(result)}.`,
10921087
fieldNodes
10931088
);
10941089
}
10951090

10961091
// Collect sub-fields to execute to complete this value.
10971092
let subFieldNodes = Object.create(null);
10981093
const visitedFragmentNames = Object.create(null);
1099-
11001094
for (let i = 0; i < fieldNodes.length; i++) {
11011095
const selectionSet = fieldNodes[i].selectionSet;
11021096
if (selectionSet) {
@@ -1122,7 +1116,7 @@ function defaultResolveTypeFn(
11221116
value: mixed,
11231117
context: mixed,
11241118
info: GraphQLResolveInfo,
1125-
abstractType: GraphQLAbstractType,
1119+
abstractType: GraphQLAbstractType
11261120
): ?GraphQLObjectType | ?Promise<?GraphQLObjectType> {
11271121
const possibleTypes = info.schema.getPossibleTypes(abstractType);
11281122
const promisedIsTypeOfResults = [];

0 commit comments

Comments
 (0)