Skip to content

Commit 1fb45d3

Browse files
authored
Factor out runtime type validation
Moves runtime type validation to its own function.
1 parent 1305360 commit 1fb45d3

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/execution/execute.js

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -949,47 +949,55 @@ function completeAbstractValue(
949949
const runtimeTypePromise: Promise<GraphQLObjectType | string> =
950950
(runtimeType: any);
951951
return runtimeTypePromise.then(resolvedRuntimeType =>
952-
validateRuntimeTypeAndCompleteObjectValue(
952+
completeObjectValue(
953953
exeContext,
954954
returnType,
955955
fieldNodes,
956956
info,
957957
path,
958-
ensureType(exeContext.schema, resolvedRuntimeType),
958+
ensureValidRuntimeType(
959+
resolvedRuntimeType,
960+
exeContext,
961+
returnType,
962+
fieldNodes,
963+
info,
964+
result
965+
),
959966
result
960967
)
961968
);
962969
}
963970

964-
return validateRuntimeTypeAndCompleteObjectValue(
971+
return completeObjectValue(
965972
exeContext,
966973
returnType,
967974
fieldNodes,
968975
info,
969976
path,
970-
ensureType(exeContext.schema, runtimeType),
977+
ensureValidRuntimeType(
978+
resolvedRuntimeType,
979+
exeContext,
980+
returnType,
981+
fieldNodes,
982+
info,
983+
result
984+
),
971985
result
972986
);
973987
}
974988

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-
984-
function validateRuntimeTypeAndCompleteObjectValue(
989+
function ensureValidRuntimeType(
990+
runtimeTypeOrName: string | GraphQLObjectType | void
985991
exeContext: ExecutionContext,
986992
returnType: GraphQLAbstractType,
987993
fieldNodes: Array<FieldNode>,
988994
info: GraphQLResolveInfo,
989-
path: ResponsePath,
990-
runtimeType: GraphQLObjectType,
991995
result: mixed
992-
): mixed {
996+
): GraphQLObjectType {
997+
const runtimeType = typeof runtimeTypeOrName === 'string' ?
998+
exeContext.schema.getType(runtimeTypeOrName) :
999+
runtimeTypeOrName;
1000+
9931001
if (!(runtimeType instanceof GraphQLObjectType)) {
9941002
throw new GraphQLError(
9951003
`Abstract type ${returnType.name} must resolve to an Object type at ` +
@@ -1007,14 +1015,7 @@ function validateRuntimeTypeAndCompleteObjectValue(
10071015
);
10081016
}
10091017

1010-
return completeObjectValue(
1011-
exeContext,
1012-
runtimeType,
1013-
fieldNodes,
1014-
info,
1015-
path,
1016-
result
1017-
);
1018+
return runtimeType;
10181019
}
10191020

10201021
/**

0 commit comments

Comments
 (0)