Skip to content

Commit ae12676

Browse files
committed
remove interface inheritance from validate relationship directive rule
1 parent f78c5cb commit ae12676

File tree

2 files changed

+5
-38
lines changed

2 files changed

+5
-38
lines changed

packages/graphql/src/schema/validation/custom-rules/directives/relationship.ts

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { DocumentValidationError } from "../utils/document-validation-error";
3131

3232
export function verifyRelationshipArgumentValue(
3333
objectTypeToRelationshipsPerRelationshipTypeMap: Map<string, Map<string, [string, string, string][]>>,
34-
interfaceToImplementationsMap: Map<string, Set<string>>,
3534
extra?: {
3635
enums: EnumTypeDefinitionNode[];
3736
interfaces: InterfaceTypeDefinitionNode[];
@@ -51,8 +50,8 @@ export function verifyRelationshipArgumentValue(
5150
// delegate
5251
return;
5352
}
54-
if (!parentDef) {
55-
console.error("No parent definition");
53+
if (!parentDef || parentDef.kind === Kind.INTERFACE_TYPE_DEFINITION) {
54+
// @relationship can only be present on fields of Object Types
5655
return;
5756
}
5857
const typeArg = directiveNode.arguments?.find((a) => a.name.value === "type");
@@ -72,8 +71,7 @@ export function verifyRelationshipArgumentValue(
7271
parentDef,
7372
currentRelationship,
7473
typeValue,
75-
objectTypeToRelationshipsPerRelationshipTypeMap,
76-
interfaceToImplementationsMap
74+
objectTypeToRelationshipsPerRelationshipTypeMap
7775
);
7876
}
7977

@@ -149,44 +147,17 @@ function checkRelationshipFieldsForDuplicates(
149147
}
150148

151149
function verifyRelationshipFields(
152-
parentDef: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
150+
parentDef: ObjectTypeDefinitionNode,
153151
currentRelationship: [string, string, string],
154152
typeValue: any,
155-
objectTypeToRelationshipsPerRelationshipTypeMap: Map<string, Map<string, [string, string, string][]>>,
156-
interfaceToImplementationsMap: Map<string, Set<string>>
153+
objectTypeToRelationshipsPerRelationshipTypeMap: Map<string, Map<string, [string, string, string][]>>
157154
) {
158155
const relationshipFieldsForCurrentType = objectTypeToRelationshipsPerRelationshipTypeMap.get(parentDef.name.value);
159156
checkRelationshipFieldsForDuplicates(relationshipFieldsForCurrentType, currentRelationship, typeValue);
160157
objectTypeToRelationshipsPerRelationshipTypeMap.set(
161158
parentDef.name.value,
162159
getUpdatedRelationshipFieldsForCurrentType(relationshipFieldsForCurrentType, currentRelationship, typeValue)
163160
);
164-
165-
if (parentDef.kind === Kind.INTERFACE_TYPE_DEFINITION) {
166-
const dependents = interfaceToImplementationsMap.get(parentDef.name.value);
167-
dependents?.forEach((dependentTypeName) => {
168-
const relationshipFieldsForDependentType =
169-
objectTypeToRelationshipsPerRelationshipTypeMap.get(dependentTypeName);
170-
checkRelationshipFieldsForDuplicates(relationshipFieldsForDependentType, currentRelationship, typeValue);
171-
});
172-
}
173-
174-
if (parentDef.kind === Kind.OBJECT_TYPE_DEFINITION) {
175-
parentDef.interfaces?.forEach((i) => {
176-
const relationshipFieldsForImplementedInterface = objectTypeToRelationshipsPerRelationshipTypeMap.get(
177-
i.name.value
178-
);
179-
checkRelationshipFieldsForDuplicates(
180-
relationshipFieldsForImplementedInterface,
181-
currentRelationship,
182-
typeValue
183-
);
184-
185-
const implementations = interfaceToImplementationsMap.get(i.name.value) || new Set<string>();
186-
implementations.add(parentDef.name.value);
187-
interfaceToImplementationsMap.set(i.name.value, implementations);
188-
});
189-
}
190161
}
191162

192163
export function verifyRelationshipFieldType({

packages/graphql/src/schema/validation/custom-rules/directives/valid-directive.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ function getValidationFunction(
4343
string,
4444
Map<string, [string, string, string][]>
4545
>,
46-
interfaceToImplementationsMap: Map<string, Set<string>>,
4746
extra: {
4847
enums: EnumTypeDefinitionNode[];
4948
interfaces: InterfaceTypeDefinitionNode[];
@@ -66,7 +65,6 @@ function getValidationFunction(
6665
case "relationship":
6766
return verifyRelationshipArgumentValue(
6867
objectTypeToFieldNameDirectionAndFieldTypePerRelationshipTypeMap,
69-
interfaceToImplementationsMap,
7068
extra
7169
);
7270
default:
@@ -108,13 +106,11 @@ export function directiveIsValid(
108106
string,
109107
Map<string, [string, string, string][]>
110108
>();
111-
const interfaceToImplementationsMap = new Map<string, Set<string>>();
112109
return {
113110
Directive(directiveNode: DirectiveNode, _key, _parent, path, ancenstors) {
114111
const validationFn = getValidationFunction(
115112
directiveNode.name.value,
116113
objectTypeToFieldNameDirectionAndFieldTypePerRelationshipTypeMap,
117-
interfaceToImplementationsMap,
118114
extra,
119115
callbacks
120116
);

0 commit comments

Comments
 (0)