Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graphql): similar directive sdls on multiple fields fail #2559

Merged
merged 4 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import { MetadataListByNameCollection } from './metadata-list-by-name.collection
export class FieldDirectiveCollection extends MetadataListByNameCollection<PropertyDirectiveMetadata> {
sdls = new Set<string>();
fieldNames = new Set<string>();
uniqueCombinations = new Set<string>();

add(value: PropertyDirectiveMetadata) {
if (this.sdls.has(value.sdl) && this.fieldNames.has(value.fieldName)) {
return;
const combinationKey = `${value.sdl}${value.fieldName}`;
if (this.uniqueCombinations.has(combinationKey)) {
return;
kamilmysliwiec marked this conversation as resolved.
Show resolved Hide resolved
}

super.add(value, value.fieldName);

this.sdls.add(value.sdl);
this.fieldNames.add(value.fieldName);
this.uniqueCombinations.add(combinationKey);
this.globalArray?.push(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ describe('FieldDirectiveCollection', () => {
expect(map.getByName('bar')).toEqual([directive1Alt]);
});

it('should add 2 different fields with the same directives', () => {
const map = new FieldDirectiveCollection();
const directive1Alt: PropertyDirectiveMetadata = {
fieldName: 'bar',
sdl: '@foo',
target: () => {},
};
const directive2Alt: PropertyDirectiveMetadata = {
fieldName: 'foo',
sdl: '@bar',
target: () => {},
};
map.add(directive1);
map.add(directive2);
map.add(directive1Alt);
map.add(directive2Alt);

expect(map.getByName('foo')).toEqual([directive1, directive2Alt]);
expect(map.getByName('bar')).toEqual([directive2, directive1Alt]);
});

it('should NOT the same directive on the same field twice', () => {
const map = new FieldDirectiveCollection();
map.add(directive1);
Expand Down