Skip to content

Commit 225cab9

Browse files
committed
rename runtimeType(Name) to possibleRuntimeType(Name)
because it could not be the runtime type(name), could be an intermediate interface I considered just renaming it to resolvedTypeName, but that's confusing, because the variable could hold a promise, and resolvedResolvedTypeName overloads "resolve"
1 parent 9e0c4d0 commit 225cab9

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/execution/execute.ts

+25-21
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ function completeAbstractValue(
799799
): PromiseOrValue<ObjMap<unknown>> {
800800
const resolveTypeFn = abstractType.resolveType ?? exeContext.typeResolver;
801801
const contextValue = exeContext.contextValue;
802-
const runtimeTypeName = resolveTypeFn(
802+
const possibleRuntimeTypeName = resolveTypeFn(
803803
result,
804804
contextValue,
805805
info,
@@ -809,7 +809,7 @@ function completeAbstractValue(
809809
return completeAbstractValueImpl(
810810
exeContext,
811811
abstractType,
812-
runtimeTypeName,
812+
possibleRuntimeTypeName,
813813
fieldNodes,
814814
info,
815815
path,
@@ -820,14 +820,14 @@ function completeAbstractValue(
820820
function completeAbstractValueImpl(
821821
exeContext: ExecutionContext,
822822
abstractType: GraphQLAbstractType,
823-
runtimeTypeName: PromiseOrValue<string | undefined>,
823+
possibleRuntimeTypeName: PromiseOrValue<string | undefined>,
824824
fieldNodes: ReadonlyArray<FieldNode>,
825825
info: GraphQLResolveInfo,
826826
path: Path,
827827
result: unknown,
828828
): PromiseOrValue<ObjMap<unknown>> {
829-
if (isPromise(runtimeTypeName)) {
830-
return runtimeTypeName.then((resolved) =>
829+
if (isPromise(possibleRuntimeTypeName)) {
830+
return possibleRuntimeTypeName.then((resolved) =>
831831
completeAbstractValueImpl(
832832
exeContext,
833833
abstractType,
@@ -840,7 +840,7 @@ function completeAbstractValueImpl(
840840
);
841841
}
842842

843-
if (runtimeTypeName == null) {
843+
if (possibleRuntimeTypeName == null) {
844844
throw new GraphQLError(
845845
`Abstract type "${abstractType.name}" must resolve to an Object type or an intermediate Interface type at runtime for field "${info.parentType.name}.${info.fieldName}". Either the "${abstractType.name}" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`,
846846
{ nodes: fieldNodes },
@@ -849,61 +849,65 @@ function completeAbstractValueImpl(
849849

850850
// releases before 16.0.0 supported returning `GraphQLObjectType` from `resolveType`
851851
// TODO: remove in 17.0.0 release
852-
if (isObjectType(runtimeTypeName)) {
852+
if (isObjectType(possibleRuntimeTypeName)) {
853853
throw new GraphQLError(
854854
'Support for returning GraphQLObjectType from resolveType was removed in [email protected] please return type name instead.',
855855
);
856856
}
857857

858-
if (typeof runtimeTypeName !== 'string') {
858+
if (typeof possibleRuntimeTypeName !== 'string') {
859859
throw new GraphQLError(
860860
`Abstract type "${abstractType.name}" must resolve to an Object type or an intermediate Interface type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` +
861-
`value ${inspect(result)}, received "${inspect(runtimeTypeName)}".`,
861+
`value ${inspect(result)}, received "${inspect(
862+
possibleRuntimeTypeName,
863+
)}".`,
862864
);
863865
}
864866

865-
const runtimeType = exeContext.schema.getType(runtimeTypeName);
866-
if (runtimeType == null) {
867+
const possibleRuntimeType = exeContext.schema.getType(
868+
possibleRuntimeTypeName,
869+
);
870+
if (possibleRuntimeType == null) {
867871
throw new GraphQLError(
868-
`Abstract type "${abstractType.name}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`,
872+
`Abstract type "${abstractType.name}" was resolved to a type "${possibleRuntimeTypeName}" that does not exist inside the schema.`,
869873
{ nodes: fieldNodes },
870874
);
871875
}
872876

873-
if (isInterfaceType(runtimeType)) {
874-
if (!exeContext.schema.isSubType(abstractType, runtimeType)) {
877+
if (isInterfaceType(possibleRuntimeType)) {
878+
if (!exeContext.schema.isSubType(abstractType, possibleRuntimeType)) {
875879
throw new GraphQLError(
876-
`Interface type "${runtimeType.name}" is not a possible type for "${abstractType.name}".`,
880+
`Interface type "${possibleRuntimeType.name}" is not a possible type for "${abstractType.name}".`,
877881
{ nodes: fieldNodes },
878882
);
879883
}
880884

881885
return completeAbstractValue(
882886
exeContext,
883-
runtimeType,
887+
possibleRuntimeType,
884888
fieldNodes,
885889
info,
886890
path,
887891
result,
888892
);
889893
}
890894

891-
if (!isObjectType(runtimeType)) {
895+
if (!isObjectType(possibleRuntimeType)) {
892896
throw new GraphQLError(
893-
`Abstract type "${abstractType.name}" was resolved to a non-object and non-interface type "${runtimeTypeName}".`,
897+
`Abstract type "${abstractType.name}" was resolved to a non-object and non-interface type "${possibleRuntimeTypeName}".`,
894898
{ nodes: fieldNodes },
895899
);
896900
}
897901

898-
if (!exeContext.schema.isSubType(abstractType, runtimeType)) {
902+
if (!exeContext.schema.isSubType(abstractType, possibleRuntimeType)) {
899903
throw new GraphQLError(
900-
`Runtime Object type "${runtimeType.name}" is not a possible type for "${abstractType.name}".`,
904+
`Runtime Object type "${possibleRuntimeType.name}" is not a possible type for "${abstractType.name}".`,
901905
{ nodes: fieldNodes },
902906
);
903907
}
904908
return completeObjectValue(
905909
exeContext,
906-
runtimeType,
910+
possibleRuntimeType,
907911
fieldNodes,
908912
info,
909913
path,

0 commit comments

Comments
 (0)