Skip to content

Commit 9e0c4d0

Browse files
committed
re-align error message as possible to original
1 parent 5ba43d8 commit 9e0c4d0

File tree

2 files changed

+26
-40
lines changed

2 files changed

+26
-40
lines changed

src/execution/__tests__/abstract-test.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ describe('Execute: Handles execution of abstract types', () => {
271271
errors: [
272272
{
273273
message:
274-
'Abstract type resolution for "Pet" for field "Query.pet" failed. Encountered abstract type "Pet" must resolve to an Object or Interface type at runtime. Either the "Pet" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.',
274+
'Abstract type "Pet" must resolve to an Object type or an intermediate Interface type at runtime for field "Query.pet". Either the "Pet" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.',
275275
locations: [{ line: 3, column: 9 }],
276276
path: ['pet'],
277277
},
@@ -610,26 +610,26 @@ describe('Execute: Handles execution of abstract types', () => {
610610
}
611611

612612
expectError({ forTypeName: undefined }).toEqual(
613-
'Abstract type resolution for "Pet" for field "Query.pet" failed. Encountered abstract type "Pet" must resolve to an Object or Interface type at runtime. Either the "Pet" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.',
613+
'Abstract type "Pet" must resolve to an Object type or an intermediate Interface type at runtime for field "Query.pet". Either the "Pet" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.',
614614
);
615615

616616
expectError({ forTypeName: 'Human' }).toEqual(
617-
'Abstract type resolution for "Pet" for field "Query.pet" failed. Encountered abstract type "Pet" was resolved to a type "Human" that does not exist inside the schema.',
617+
'Abstract type "Pet" was resolved to a type "Human" that does not exist inside the schema.',
618618
);
619619

620620
expectError({ forTypeName: 'String' }).toEqual(
621-
'Abstract type resolution for "Pet" for field "Query.pet" failed. Encountered abstract type "Pet" was resolved to a non-object type "String".',
621+
'Abstract type "Pet" was resolved to a non-object and non-interface type "String".',
622622
);
623623

624624
expectError({ forTypeName: '__Schema' }).toEqual(
625-
'Abstract type resolution for "Pet" for field "Query.pet" failed. Runtime Object type "__Schema" is not a possible type for encountered abstract type "Pet".',
625+
'Runtime Object type "__Schema" is not a possible type for "Pet".',
626626
);
627627

628628
// FIXME: workaround since we can't inject resolveType into SDL
629629
// @ts-expect-error
630630
assertInterfaceType(schema.getType('Pet')).resolveType = () => [];
631631
expectError({ forTypeName: undefined }).toEqual(
632-
'Abstract type resolution for "Pet" for field "Query.pet" with value { __typename: undefined } failed. Encountered abstract type "Pet" must resolve to an Object or Interface type at runtime, received "[]".',
632+
'Abstract type "Pet" must resolve to an Object type or an intermediate Interface type at runtime for field "Query.pet" with value { __typename: undefined }, received "[]".',
633633
);
634634

635635
// FIXME: workaround since we can't inject resolveType into SDL
@@ -706,53 +706,53 @@ describe('Execute: Handles execution of abstract types', () => {
706706
// FIXME: workaround since we can't inject resolveType into SDL
707707
namedType.resolveType = () => 'Animal';
708708
expectError().toEqual(
709-
'Abstract type resolution for "Named" for field "Query.named" failed. Interface type "Animal" is not a subtype of encountered interface type "Named".',
709+
'Interface type "Animal" is not a possible type for "Named".',
710710
);
711711

712712
const petType = assertInterfaceType(schema.getType('Pet'));
713713
// FIXME: workaround since we can't inject resolveType into SDL
714714
namedType.resolveType = () => 'Pet';
715715
petType.resolveType = () => 'Person';
716716
expectError().toEqual(
717-
'Abstract type resolution for "Named" for field "Query.named" failed. Runtime Object type "Person" is not a possible type for encountered abstract type "Pet".',
717+
'Runtime Object type "Person" is not a possible type for "Pet".',
718718
);
719719

720720
// FIXME: workaround since we can't inject resolveType into SDL
721721
namedType.resolveType = () => 'Pet';
722722
petType.resolveType = () => undefined;
723723
expectError().toEqual(
724-
'Abstract type resolution for "Named" for field "Query.named" failed. Encountered abstract type "Pet" must resolve to an Object or Interface type at runtime. Either the "Pet" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.',
724+
'Abstract type "Pet" must resolve to an Object type or an intermediate Interface type at runtime for field "Query.named". Either the "Pet" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.',
725725
);
726726

727727
// FIXME: workaround since we can't inject resolveType into SDL
728728
petType.resolveType = () => 'Human';
729729
expectError().toEqual(
730-
'Abstract type resolution for "Named" for field "Query.named" failed. Encountered abstract type "Pet" was resolved to a type "Human" that does not exist inside the schema.',
730+
'Abstract type "Pet" was resolved to a type "Human" that does not exist inside the schema.',
731731
);
732732

733733
// FIXME: workaround since we can't inject resolveType into SDL
734734
petType.resolveType = () => 'String';
735735
expectError().toEqual(
736-
'Abstract type resolution for "Named" for field "Query.named" failed. Encountered abstract type "Pet" was resolved to a non-object type "String".',
736+
'Abstract type "Pet" was resolved to a non-object and non-interface type "String".',
737737
);
738738

739739
// FIXME: workaround since we can't inject resolveType into SDL
740740
petType.resolveType = () => '__Schema';
741741
expectError().toEqual(
742-
'Abstract type resolution for "Named" for field "Query.named" failed. Runtime Object type "__Schema" is not a possible type for encountered abstract type "Pet".',
742+
'Runtime Object type "__Schema" is not a possible type for "Pet".',
743743
);
744744

745745
// FIXME: workaround since we can't inject resolveType into SDL
746746
// @ts-expect-error
747747
petType.resolveType = () => [];
748748
expectError().toEqual(
749-
'Abstract type resolution for "Named" for field "Query.named" with value {} failed. Encountered abstract type "Pet" must resolve to an Object or Interface type at runtime, received "[]".',
749+
'Abstract type "Pet" must resolve to an Object type or an intermediate Interface type at runtime for field "Query.named" with value {}, received "[]".',
750750
);
751751

752752
// FIXME: workaround since we can't inject resolveType into SDL
753753
petType.resolveType = () => 'Pet';
754754
expectError().toEqual(
755-
'Abstract type resolution for "Named" for field "Query.named" failed. Interface type "Pet" is not a subtype of encountered interface type "Named".',
755+
'Interface type "Pet" is not a possible type for "Pet".',
756756
);
757757
});
758758
});

src/execution/execute.ts

+12-26
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ function completeValue(
668668
return completeAbstractValue(
669669
exeContext,
670670
returnType,
671-
returnType,
672671
fieldNodes,
673672
info,
674673
path,
@@ -792,7 +791,6 @@ function completeLeafValue(
792791
*/
793792
function completeAbstractValue(
794793
exeContext: ExecutionContext,
795-
returnType: GraphQLAbstractType,
796794
abstractType: GraphQLAbstractType,
797795
fieldNodes: ReadonlyArray<FieldNode>,
798796
info: GraphQLResolveInfo,
@@ -810,7 +808,6 @@ function completeAbstractValue(
810808

811809
return completeAbstractValueImpl(
812810
exeContext,
813-
returnType,
814811
abstractType,
815812
runtimeTypeName,
816813
fieldNodes,
@@ -822,8 +819,7 @@ function completeAbstractValue(
822819

823820
function completeAbstractValueImpl(
824821
exeContext: ExecutionContext,
825-
returnType: GraphQLAbstractType,
826-
currentAbstractType: GraphQLAbstractType,
822+
abstractType: GraphQLAbstractType,
827823
runtimeTypeName: PromiseOrValue<string | undefined>,
828824
fieldNodes: ReadonlyArray<FieldNode>,
829825
info: GraphQLResolveInfo,
@@ -834,8 +830,7 @@ function completeAbstractValueImpl(
834830
return runtimeTypeName.then((resolved) =>
835831
completeAbstractValueImpl(
836832
exeContext,
837-
returnType,
838-
currentAbstractType,
833+
abstractType,
839834
resolved,
840835
fieldNodes,
841836
info,
@@ -847,9 +842,7 @@ function completeAbstractValueImpl(
847842

848843
if (runtimeTypeName == null) {
849844
throw new GraphQLError(
850-
`Abstract type resolution for "${returnType.name}" for field "${info.parentType.name}.${info.fieldName}" failed. ` +
851-
`Encountered abstract type "${currentAbstractType.name}" must resolve to an Object or Interface type at runtime. ` +
852-
`Either the "${currentAbstractType.name}" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`,
845+
`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.`,
853846
{ nodes: fieldNodes },
854847
);
855848
}
@@ -864,33 +857,29 @@ function completeAbstractValueImpl(
864857

865858
if (typeof runtimeTypeName !== 'string') {
866859
throw new GraphQLError(
867-
`Abstract type resolution for "${returnType.name}" for field "${info.parentType.name}.${info.fieldName}" ` +
868-
`with value ${inspect(result)} failed. ` +
869-
`Encountered abstract type "${currentAbstractType.name}" must resolve to an Object or Interface type at runtime, ` +
870-
`received "${inspect(runtimeTypeName)}".`,
860+
`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)}".`,
871862
);
872863
}
873864

874865
const runtimeType = exeContext.schema.getType(runtimeTypeName);
875866
if (runtimeType == null) {
876867
throw new GraphQLError(
877-
`Abstract type resolution for "${returnType.name}" for field "${info.parentType.name}.${info.fieldName}" failed. ` +
878-
`Encountered abstract type "${currentAbstractType.name}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`,
868+
`Abstract type "${abstractType.name}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`,
879869
{ nodes: fieldNodes },
880870
);
881871
}
882872

883873
if (isInterfaceType(runtimeType)) {
884-
if (!exeContext.schema.isSubType(currentAbstractType, runtimeType)) {
874+
if (!exeContext.schema.isSubType(abstractType, runtimeType)) {
885875
throw new GraphQLError(
886-
`Abstract type resolution for "${returnType.name}" for field "${info.parentType.name}.${info.fieldName}" failed. ` +
887-
`Interface type "${runtimeType.name}" is not a subtype of encountered interface type "${returnType.name}".`,
876+
`Interface type "${runtimeType.name}" is not a possible type for "${abstractType.name}".`,
888877
{ nodes: fieldNodes },
889878
);
890879
}
880+
891881
return completeAbstractValue(
892882
exeContext,
893-
returnType,
894883
runtimeType,
895884
fieldNodes,
896885
info,
@@ -901,20 +890,17 @@ function completeAbstractValueImpl(
901890

902891
if (!isObjectType(runtimeType)) {
903892
throw new GraphQLError(
904-
`Abstract type resolution for "${returnType.name}" for field "${info.parentType.name}.${info.fieldName}" failed. ` +
905-
`Encountered abstract type "${currentAbstractType.name}" was resolved to a non-object type "${runtimeTypeName}".`,
893+
`Abstract type "${abstractType.name}" was resolved to a non-object and non-interface type "${runtimeTypeName}".`,
906894
{ nodes: fieldNodes },
907895
);
908896
}
909897

910-
if (!exeContext.schema.isSubType(currentAbstractType, runtimeType)) {
898+
if (!exeContext.schema.isSubType(abstractType, runtimeType)) {
911899
throw new GraphQLError(
912-
`Abstract type resolution for "${returnType.name}" for field "${info.parentType.name}.${info.fieldName}" failed. ` +
913-
`Runtime Object type "${runtimeType.name}" is not a possible type for encountered abstract type "${currentAbstractType.name}".`,
900+
`Runtime Object type "${runtimeType.name}" is not a possible type for "${abstractType.name}".`,
914901
{ nodes: fieldNodes },
915902
);
916903
}
917-
918904
return completeObjectValue(
919905
exeContext,
920906
runtimeType,

0 commit comments

Comments
 (0)