Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions composition/src/ast/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ import {
SCHEMA_UPPER,
SUBSCRIPTION,
UNION_UPPER,
VALID_PROVIDES_PARENT_KINDS,
} from '../utils/string-constants';
import {
CompositeOutputData,
type ParentDefinitionData,
UnionDefinitionData,
type ValidProvidesParentData,
} from '../schema-building/types/types';

export function isObjectLikeNodeEntity(node: CompositeOutputNode): boolean {
if (!node.directives?.length) {
Expand Down Expand Up @@ -301,3 +308,7 @@ export type ParentTypeNode =
export type InterfaceNodeKind = Kind.INTERFACE_TYPE_DEFINITION | Kind.INTERFACE_TYPE_EXTENSION;
export type ObjectNodeKind = Kind.OBJECT_TYPE_DEFINITION | Kind.OBJECT_TYPE_EXTENSION;
export type CompositeOutputNodeKind = InterfaceNodeKind | ObjectNodeKind;

export function isValidProvidesParentData(data: ParentDefinitionData): data is ValidProvidesParentData {
return VALID_PROVIDES_PARENT_KINDS.has(data.kind);
}
76 changes: 66 additions & 10 deletions composition/src/errors/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
type ObjectDefinitionData,
} from '../schema-building/types/types';
import {
type InvalidEntityReturnTypeErrorParams,
type IncompatibleMergedTypesErrorParams,
type IncompatibleParentTypeMergeErrorParams,
type IncompatibleTypeWithProvidesErrorMessageParams,
type InvalidArgumentValueErrorParams,
type InvalidCustomDirectiveErrorParams,
type InvalidDirectiveLocationErrorParams,
type InvalidEntityReturnTypeErrorParams,
type InvalidLinkDirectiveImportObjectErrorParams,
type InvalidNamedTypeErrorParams,
type InvalidRepeatedDirectiveErrorParams,
Expand All @@ -36,6 +36,7 @@ import {
LITERAL_NEW_LINE,
LITERAL_PERIOD,
NOT_UPPER,
OBJECT,
OR_UPPER,
QUOTATION_JOIN,
SUBSCRIPTION_FIELD_CONDITION,
Expand Down Expand Up @@ -771,14 +772,14 @@ export function duplicateFieldInFieldSetErrorMessage(fieldSet: string, fieldPath
);
}

export function incompatibleTypeWithProvidesErrorMessage({
export function incompatibleTypeWithProvidesError({
fieldCoords,
responseType,
subgraphName,
}: IncompatibleTypeWithProvidesErrorMessageParams): string {
return (
}: IncompatibleTypeWithProvidesErrorMessageParams): Error {
return new Error(
` A "@provides" directive is declared on field "${fieldCoords}" in subgraph "${subgraphName}".\n` +
` However, the response type "${responseType}" is not an Object nor Interface.`
` However, the response type "${responseType}" is not an Object, Interface, nor Union.`,
);
}

Expand Down Expand Up @@ -828,8 +829,7 @@ export function invalidInlineFragmentTypeErrorMessage(
` This is because an inline fragment with the type condition "${typeConditionName}" is defined on the` +
` selection set corresponding to the ` +
getSelectionSetLocation(fieldCoordinatesPath, selectionSetTypeName, true) +
` However, "${selectionSetTypeName}" is not an abstract (Interface or Union) type.\n` +
` Consequently, the only valid type condition at this selection set would be "${selectionSetTypeName}".`
` However, "${selectionSetTypeName}" is not an abstract (Interface or Union) type and is therefore incompatible.`
);
}

Expand Down Expand Up @@ -877,16 +877,72 @@ export function invalidInlineFragmentTypeConditionErrorMessage(
typeConditionName: string,
parentTypeString: string,
selectionSetTypeName: string,
typeConditionTypeString: string,
): string {
const message =
` The following field set is invalid:\n "${fieldSet}"\n` +
` This is because an inline fragment with the type condition "${typeConditionName}" is defined on the` +
` selection set corresponding to the ` +
getSelectionSetLocationWithTypeString(fieldCoordinatesPath, selectionSetTypeName, parentTypeString);
if (parentTypeString === INTERFACE) {
return message + ` However, "${typeConditionName}" does not implement "${selectionSetTypeName}"`;
switch (parentTypeString) {
case INTERFACE: {
switch (typeConditionTypeString) {
case INTERFACE: {
return (
message +
` However, Interfaces "${typeConditionName}" and "${selectionSetTypeName}" are neither an` +
` implementation of the other.`
);
}
case OBJECT: {
return (
message + ` However, Object "${typeConditionName}" does not implement Interface "${selectionSetTypeName}".`
);
}
case UNION: {
return (
message +
` However, no members of Union "${typeConditionName}" implement Interface "${selectionSetTypeName}".`
);
}
}
break;
}
case OBJECT: {
switch (typeConditionTypeString) {
case INTERFACE: {
return (
message + ` However, Object "${selectionSetTypeName}" does not implement Interface "${typeConditionName}".`
);
}
case UNION: {
return (
message + ` However, Object "${selectionSetTypeName}" is not a member of Union "${typeConditionName}".`
);
}
}
break;
}
case UNION: {
switch (typeConditionTypeString) {
case INTERFACE: {
return message + ` However, no members of Union "${selectionSetTypeName}" implement "${typeConditionName}".`;
}
case OBJECT: {
return (
message + ` However, Object "${typeConditionName}" is not a member of Union "${selectionSetTypeName}".`
);
}
case UNION: {
return (
message + ` However, Unions "${typeConditionName}" and "${selectionSetTypeName}" share no mutual members.`
);
}
}
break;
}
}
return message + ` However, "${typeConditionName}" is not a member of "${selectionSetTypeName}".`;
return message;
}

export function invalidSelectionOnUnionErrorMessage(
Expand Down
2 changes: 2 additions & 0 deletions composition/src/schema-building/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ export type ChildData = EnumValueData | FieldData | InputValueData;

export type CompositeOutputData = InterfaceDefinitionData | ObjectDefinitionData;

export type ValidProvidesParentData = CompositeOutputData | UnionDefinitionData;

export type DefinitionData =
| DirectiveArgumentData
| DirectiveDefinitionData
Expand Down
6 changes: 6 additions & 0 deletions composition/src/utils/string-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,9 @@ export const OUTPUT_NODE_KINDS = new Set<Kind>([
export const INTERFACE_NODE_KINDS = new Set<Kind>([Kind.INTERFACE_TYPE_DEFINITION, Kind.INTERFACE_TYPE_EXTENSION]);

export const NON_REPEATABLE_FEDERATED_DIRECTIVES = new Set<DirectiveName>([INACCESSIBLE, ONE_OF, SEMANTIC_NON_NULL]);

export const VALID_PROVIDES_PARENT_KINDS = new Set<Kind>([
Kind.INTERFACE_TYPE_DEFINITION,
Kind.OBJECT_TYPE_DEFINITION,
Kind.UNION_TYPE_DEFINITION,
]);
Loading
Loading