diff --git a/.changeset/thin-pandas-fetch.md b/.changeset/thin-pandas-fetch.md new file mode 100644 index 00000000..435e0075 --- /dev/null +++ b/.changeset/thin-pandas-fetch.md @@ -0,0 +1,5 @@ +--- +"@theguild/federation-composition": patch +--- + +Fix in containsSupergraphSpec to treat directive definition as actual definition diff --git a/__tests__/subgraph-validation-and-compositon-root-query.spec.ts b/__tests__/subgraph-validation-and-compositon-root-query.spec.ts index 4abd8137..3e43926b 100644 --- a/__tests__/subgraph-validation-and-compositon-root-query.spec.ts +++ b/__tests__/subgraph-validation-and-compositon-root-query.spec.ts @@ -3,6 +3,7 @@ import { describe, expect, test } from "vitest"; import { assertCompositionSuccess, composeServices } from "../src/compose.js"; import { ServiceDefinition } from "../src/types.js"; import { validate } from "../src/validate.js"; +import { containsSupergraphSpec } from "../src/graphql/contains-supergraph-spec.js"; const serviceA: ServiceDefinition = { name: "serviceA", @@ -51,8 +52,7 @@ describe("Test to validate custom root query is treated as Query", () => { const hasCustomRootQueryAsObjectType = supergraph.some( (def) => def.kind === Kind.OBJECT_TYPE_DEFINITION && - (def.name.value === "RootQuery" || - def.name.value === "CustomQueryName"), + (def.name.value === "RootQuery" || def.name.value === "CustomQueryName") ); expect(hasCustomRootQueryAsObjectType).eq(false); @@ -76,3 +76,23 @@ describe("Test to validate custom root query is treated as Query", () => { } }); }); + +describe("Test to validate monolith schema is not treated as supergraph spec", () => { + test("Shouldn't treat properties with spec directive names as supergraph spec", () => { + const isSupergraph = containsSupergraphSpec(`#graphql + schema { + query: RootQueryType + } + + type Link { + link: String + } + + type RootQueryType { + foo: Link + } + `); + + expect(isSupergraph).eq(false); + }); +}); diff --git a/src/graphql/contains-supergraph-spec.ts b/src/graphql/contains-supergraph-spec.ts index 733932be..c53bfcbf 100644 --- a/src/graphql/contains-supergraph-spec.ts +++ b/src/graphql/contains-supergraph-spec.ts @@ -15,7 +15,7 @@ export function containsSupergraphSpec(sdl: string): boolean { const patterns: string[] = []; for (const { name, kind } of getSupergraphSpecNodes()) { - if (kind === Kind.DIRECTIVE) { + if (kind === Kind.DIRECTIVE || kind === Kind.DIRECTIVE_DEFINITION) { // "@NAME" for directives patterns.push(`@${name}`); } else {