Skip to content

Commit fe47b12

Browse files
committed
fix: containsSupergraphSpec to treat directive definition as actual definition
1 parent 5076dac commit fe47b12

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

.changeset/thin-pandas-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@theguild/federation-composition": patch
3+
---
4+
5+
Fix in containsSupergraphSpec to treat directive definition as actual definition

__tests__/subgraph-validation-and-compositon-root-query.spec.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Kind, parse } from "graphql";
1+
import { graphql, Kind, parse } from "graphql";
22
import { describe, expect, test } from "vitest";
33
import { assertCompositionSuccess, composeServices } from "../src/compose.js";
44
import { ServiceDefinition } from "../src/types.js";
55
import { validate } from "../src/validate.js";
6+
import { containsSupergraphSpec } from "../src/graphql/contains-supergraph-spec.js";
67

78
const serviceA: ServiceDefinition = {
89
name: "serviceA",
@@ -51,8 +52,7 @@ describe("Test to validate custom root query is treated as Query", () => {
5152
const hasCustomRootQueryAsObjectType = supergraph.some(
5253
(def) =>
5354
def.kind === Kind.OBJECT_TYPE_DEFINITION &&
54-
(def.name.value === "RootQuery" ||
55-
def.name.value === "CustomQueryName"),
55+
(def.name.value === "RootQuery" || def.name.value === "CustomQueryName")
5656
);
5757

5858
expect(hasCustomRootQueryAsObjectType).eq(false);
@@ -76,3 +76,23 @@ describe("Test to validate custom root query is treated as Query", () => {
7676
}
7777
});
7878
});
79+
80+
describe("Test to validate monolith schema is not treated as supergraph spec", () => {
81+
test("Shouldn't treat properties with spec directive names as supergraph spec", () => {
82+
const isSupergraph = containsSupergraphSpec(`#graphql
83+
schema {
84+
query: RootQueryType
85+
}
86+
87+
type Link {
88+
link: String
89+
}
90+
91+
type RootQueryType {
92+
foo: Link
93+
}
94+
`);
95+
96+
expect(isSupergraph).eq(false);
97+
});
98+
});

src/graphql/contains-supergraph-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function containsSupergraphSpec(sdl: string): boolean {
1515
const patterns: string[] = [];
1616

1717
for (const { name, kind } of getSupergraphSpecNodes()) {
18-
if (kind === Kind.DIRECTIVE) {
18+
if (kind === Kind.DIRECTIVE || kind === Kind.DIRECTIVE_DEFINITION) {
1919
// "@NAME" for directives
2020
patterns.push(`@${name}`);
2121
} else {

0 commit comments

Comments
 (0)