Skip to content

Commit 90727cf

Browse files
Merge pull request #2559 from harm-less/master
fix(graphql): similar directive sdls on multiple fields fail
2 parents f435852 + 0ace301 commit 90727cf

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/graphql/lib/schema-builder/collections/field-directive.collection.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ import { MetadataListByNameCollection } from './metadata-list-by-name.collection
44
export class FieldDirectiveCollection extends MetadataListByNameCollection<PropertyDirectiveMetadata> {
55
sdls = new Set<string>();
66
fieldNames = new Set<string>();
7+
uniqueCombinations = new Set<string>();
78

89
add(value: PropertyDirectiveMetadata) {
9-
if (this.sdls.has(value.sdl) && this.fieldNames.has(value.fieldName)) {
10+
const combinationKey = `${value.sdl}${value.fieldName}`;
11+
if (this.uniqueCombinations.has(combinationKey)) {
1012
return;
1113
}
1214

1315
super.add(value, value.fieldName);
1416

1517
this.sdls.add(value.sdl);
1618
this.fieldNames.add(value.fieldName);
19+
this.uniqueCombinations.add(combinationKey);
1720
this.globalArray?.push(value);
1821
}
1922
}

packages/graphql/tests/schema-builder/storages/field-directive.collection.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ describe('FieldDirectiveCollection', () => {
6363
expect(map.getByName('bar')).toEqual([directive1Alt]);
6464
});
6565

66+
it('should add 2 different fields with the same directives', () => {
67+
const map = new FieldDirectiveCollection();
68+
const directive1Alt: PropertyDirectiveMetadata = {
69+
fieldName: 'bar',
70+
sdl: '@foo',
71+
target: () => {},
72+
};
73+
const directive2Alt: PropertyDirectiveMetadata = {
74+
fieldName: 'foo',
75+
sdl: '@bar',
76+
target: () => {},
77+
};
78+
map.add(directive1);
79+
map.add(directive2);
80+
map.add(directive1Alt);
81+
map.add(directive2Alt);
82+
83+
expect(map.getByName('foo')).toEqual([directive1, directive2Alt]);
84+
expect(map.getByName('bar')).toEqual([directive2, directive1Alt]);
85+
});
86+
6687
it('should NOT the same directive on the same field twice', () => {
6788
const map = new FieldDirectiveCollection();
6889
map.add(directive1);

0 commit comments

Comments
 (0)