From c48774f8dfc008418b1edc2421a30e348f880412 Mon Sep 17 00:00:00 2001 From: TheGuildBot <59414373+theguild-bot@users.noreply.github.com> Date: Mon, 6 Jan 2025 07:10:11 -0500 Subject: [PATCH 1/3] chore(release): update monorepo packages versions (#6826) Co-authored-by: github-actions[bot] From c155133e7ade2c89c902fba2da27c7de0078f28d Mon Sep 17 00:00:00 2001 From: cdaringe Date: Sun, 23 Feb 2025 00:08:01 -0800 Subject: [PATCH 2/3] fix: link merging --- .../merge/src/typedefs-mergers/directives.ts | 17 +++++++++ packages/merge/tests/merge-typedefs.spec.ts | 35 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/packages/merge/src/typedefs-mergers/directives.ts b/packages/merge/src/typedefs-mergers/directives.ts index 44156ee7171..d0b752880ce 100644 --- a/packages/merge/src/typedefs-mergers/directives.ts +++ b/packages/merge/src/typedefs-mergers/directives.ts @@ -84,6 +84,14 @@ const matchValues = (a: ValueNode, b: ValueNode): boolean => { return false; }; +const isLinkDirective = (directive: DirectiveNode): boolean => directive.name.value === 'link'; +const getLinkDirectiveURL = (directive: DirectiveNode): string | undefined => { + const stringValue = isLinkDirective(directive) + ? directive.arguments?.find(arg => arg.name.value === 'url')?.value + : undefined; + return stringValue?.kind === 'StringValue' ? stringValue.value : undefined; +}; + const matchArguments = (a: ArgumentNode, b: ArgumentNode): boolean => a.name.value === b.name.value && a.value.kind === b.value.kind && matchValues(a.value, b.value); @@ -124,6 +132,15 @@ export function mergeDirectives( // if did not find a directive with this name on the result set already result.push(directive); } else { + if (isLinkDirective(directive) && isLinkDirective(result[firstAt])) { + const url1 = getLinkDirectiveURL(directive); + const url2 = getLinkDirectiveURL(result[firstAt]); + // if both are link directives but with different urls, do not merge them + if (url1 && url2 && url1 !== url2) { + result.push(directive); + continue; + } + } // if not repeatable and found directive with the same name already in the result set, // then merge the arguments of the existing directive and the new directive const mergedArguments = mergeArguments( diff --git a/packages/merge/tests/merge-typedefs.spec.ts b/packages/merge/tests/merge-typedefs.spec.ts index b22a4671712..7fc43e7f79c 100644 --- a/packages/merge/tests/merge-typedefs.spec.ts +++ b/packages/merge/tests/merge-typedefs.spec.ts @@ -1749,6 +1749,40 @@ describe('Merge TypeDefs', () => { expect(reformulatedGraphQL).toBeSimilarString(schemaWithDescription); }); + it('merges the directives with the same name and same arguments (@link)', () => { + const schema1 = parse(/* GraphQL */ ` + extend schema + @link( + url: "https://specs.apollo.dev/federation/v2.3" + import: ["@composeDirective", "@external", "@foo"] + ) + `); + + const schema2 = parse(/* GraphQL */ ` + extend schema + @link( + url: "https://specs.apollo.dev/federation/v2.3" + import: ["@composeDirective", "@external"] + ) + @link(url: "file://foo.org/trackable/v2.3", import: ["@trackable"]) + `); + const typeDefs = [schema1, schema2]; + const merged = mergeTypeDefs(typeDefs); + const prettyOutput = print(merged); + const prettyExpected = print( + parse(/* GraphQL */ ` + extend schema + @link( + url: "https://specs.apollo.dev/federation/v2.3" + import: ["@composeDirective", "@external", "@foo"] + ) + @link(url: "file://foo.org/trackable/v2.3", import: ["@trackable"]) # unique to schema 2 + `), + ); + expect(prettyOutput).toBeSimilarString(prettyExpected); + }); + + it('merges the directives with the same name and same arguments', () => { const directive = parse(/* GraphQL */ ` directive @link( @@ -1762,7 +1796,6 @@ describe('Merge TypeDefs', () => { const merged = mergeTypeDefs(typeDefs); expect(print(merged)).toBeSimilarString(print(directive)); }); - it('does not merge repeatable Federation directives without the same arguments', () => { const ast = parse(/* GraphQL */ ` extend schema From 9f5d65bbff9079d0f558b770eb80517d9f545ab3 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Wed, 24 Sep 2025 18:18:41 +0300 Subject: [PATCH 3/3] Format --- packages/merge/tests/merge-typedefs.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/merge/tests/merge-typedefs.spec.ts b/packages/merge/tests/merge-typedefs.spec.ts index 7fc43e7f79c..8bde0b66576 100644 --- a/packages/merge/tests/merge-typedefs.spec.ts +++ b/packages/merge/tests/merge-typedefs.spec.ts @@ -1782,7 +1782,6 @@ describe('Merge TypeDefs', () => { expect(prettyOutput).toBeSimilarString(prettyExpected); }); - it('merges the directives with the same name and same arguments', () => { const directive = parse(/* GraphQL */ ` directive @link(