From f49b35fcb4b24c8ba878db6d4129cc392b4b8f49 Mon Sep 17 00:00:00 2001 From: "Sachin D. Shinde" Date: Tue, 17 Sep 2024 10:55:07 -0700 Subject: [PATCH] Add some tests for #3134 and #3136 --- .../__tests__/compose.demandControl.test.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/composition-js/src/__tests__/compose.demandControl.test.ts b/composition-js/src/__tests__/compose.demandControl.test.ts index e2c2279b3..a9dd4333a 100644 --- a/composition-js/src/__tests__/compose.demandControl.test.ts +++ b/composition-js/src/__tests__/compose.demandControl.test.ts @@ -336,6 +336,10 @@ describe('demand control directive composition', () => { assertCompositionSuccess(result); expect(result.hints).toEqual([]); + expect(result.schema.directive(`cost`)).toBeDefined(); + expect(result.schema.directive(`listSize`)).toBeDefined(); + expect(result.schema.directive(`cost__listSize`)).toBeUndefined(); + const costDirectiveApplications = fieldWithCost(result)?.appliedDirectivesOf('cost'); expect(costDirectiveApplications?.toString()).toMatchString(`@cost(weight: 5)`); @@ -773,5 +777,38 @@ describe('demand control directive extraction', () => { } `); }); + + it('does not attempt to extract them to the subgraphs with similar spec URL', () => { + const subgraphA = { + name: 'subgraph-a', + typeDefs: asFed2SubgraphDocument(gql` + extend schema + @link(url: "https://specs.apollo.dev.foo.com/cost/v0.1") + @composeDirective(name: "@cost") + + directive @cost(weight: Int!) on FIELD_DEFINITION + + type Query { + a: Int @cost(weight: 1) + } + `) + }; + + const result = composeServices([subgraphA]); + assertCompositionSuccess(result); + const supergraph = Supergraph.build(result.supergraphSdl); + + expect(supergraph.subgraphs().get(subgraphA.name)?.toString()).toMatchString(` + schema + ${FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS} + { + query: Query + } + + type Query { + a: Int + } + `); + }); }); });