From 92e4e995a52bee0c7996f0e7fa9a252583a01ae7 Mon Sep 17 00:00:00 2001 From: Harm van der Werf Date: Fri, 16 Dec 2022 13:18:53 +0100 Subject: [PATCH 1/4] fix(graphql): similar directive sdls on multiple fields fail Similar directive sdls on multiple fields fail if applied to the same target --- .../collections/field-directive.collection.ts | 5 ++++- .../field-directive.collection.spec.ts | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts b/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts index fd42ac351..5f4febbfd 100644 --- a/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts +++ b/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts @@ -4,9 +4,11 @@ import { MetadataListByNameCollection } from './metadata-list-by-name.collection export class FieldDirectiveCollection extends MetadataListByNameCollection { sdls = new Set(); fieldNames = new Set(); + uniqueCombinations = new Set(); add(value: PropertyDirectiveMetadata) { - if (this.sdls.has(value.sdl) && this.fieldNames.has(value.fieldName)) { + const combinationKey = `${value.sdl}${value.fieldName}`; + if (this.uniqueCombinations.has(combinationKey)) { return; } @@ -14,6 +16,7 @@ export class FieldDirectiveCollection extends MetadataListByNameCollection { 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); From 83bc9cadc88a4c8231d0b1c6612e1553308b7f18 Mon Sep 17 00:00:00 2001 From: Harm van der Werf Date: Tue, 3 Jan 2023 09:08:57 +0100 Subject: [PATCH 2/4] Code style fix Co-authored-by: Kashif Ahmed <33416799+ProKashif@users.noreply.github.com> --- .../schema-builder/collections/field-directive.collection.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts b/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts index 5f4febbfd..e5f36a10d 100644 --- a/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts +++ b/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts @@ -8,9 +8,7 @@ export class FieldDirectiveCollection extends MetadataListByNameCollection Date: Mon, 6 Feb 2023 15:08:07 +0100 Subject: [PATCH 3/4] Update packages/graphql/lib/schema-builder/collections/field-directive.collection.ts --- .../schema-builder/collections/field-directive.collection.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts b/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts index e5f36a10d..f6f2434ea 100644 --- a/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts +++ b/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts @@ -8,7 +8,9 @@ export class FieldDirectiveCollection extends MetadataListByNameCollection Date: Mon, 6 Feb 2023 15:08:26 +0100 Subject: [PATCH 4/4] Update packages/graphql/lib/schema-builder/collections/field-directive.collection.ts --- .../schema-builder/collections/field-directive.collection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts b/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts index f6f2434ea..ecff0c14c 100644 --- a/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts +++ b/packages/graphql/lib/schema-builder/collections/field-directive.collection.ts @@ -9,7 +9,7 @@ export class FieldDirectiveCollection extends MetadataListByNameCollection