Skip to content

Commit fffe987

Browse files
fix: do not add inaccessible directive on federation built-in types (#295)
ix schema contract composition applying `@inaccessible` on the federation types `ContextArgument` and `FieldValue` on the supergraph SDL. This mitigates the following error in apollo-router upon processing the supergraph: ``` could not create router: Api error(s): The supergraph schema failed to produce a valid API schema: The following errors occurred: - Core feature type `join__ContextArgument` cannot use @inaccessible. - Core feature type `join__FieldValue` cannot use @inaccessible. ``` --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 8eaea33 commit fffe987

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

.changeset/lemon-pianos-slide.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@theguild/federation-composition": patch
3+
---
4+
5+
Fix schema contract composition applying `@inaccessible` on the federation types `ContextArgument` and `FieldValue` on the supergraph SDL.
6+
7+
This mitigates the following error in apollo-router upon processing the supergraph:
8+
9+
```
10+
could not create router: Api error(s): The supergraph schema failed to produce a valid API schema: The following errors occurred:
11+
- Core feature type `join__ContextArgument` cannot use @inaccessible.
12+
- Core feature type `join__FieldValue` cannot use @inaccessible.
13+
```

__tests__/contracts/add-inaccessible-to-unreachable-types.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,50 @@ test("Filters based on tags", async () => {
9898
}"
9999
`);
100100
});
101+
102+
test("Inaccessible is not added on built-in Federation types ContextArgument and FieldValue", async () => {
103+
const sdl = /* GraphQL */ `
104+
extend schema
105+
@link(url: "https://specs.apollo.dev/federation/v2.9", import: ["@key"])
106+
107+
type Query {
108+
me: Me
109+
}
110+
111+
type Me @key(fields: "id") {
112+
id: ID!
113+
}
114+
`;
115+
116+
let compositionResult = composeServices([
117+
{
118+
name: "user",
119+
url: "https://noop.graphql-hive.com",
120+
typeDefs: parse(sdl),
121+
},
122+
]);
123+
124+
expect(compositionResult.errors).toBe(undefined);
125+
expect(compositionResult.supergraphSdl).not.toBe(undefined);
126+
const { resolveImportName } = extractLinkImplementations(
127+
parse(compositionResult.supergraphSdl!),
128+
);
129+
130+
compositionResult = addInaccessibleToUnreachableTypes(
131+
resolveImportName,
132+
compositionResult as CompositionSuccess,
133+
);
134+
135+
expect(compositionResult.supergraphSdl).to.include(
136+
"scalar join__FieldValue\n",
137+
);
138+
expect(compositionResult.supergraphSdl).to.not.include(
139+
"scalar join__FieldValue @inaccessible",
140+
);
141+
expect(compositionResult.supergraphSdl).to.not.include(
142+
"input join__ContextArgument @inaccessible {",
143+
);
144+
expect(compositionResult.supergraphSdl).to.include(
145+
"input join__ContextArgument {\n",
146+
);
147+
});

src/contracts/add-inaccessible-to-unreachable-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export const addInaccessibleToUnreachableTypes = (
2828
resolveName("https://specs.apollo.dev/federation", "Policy"),
2929
resolveName("https://specs.apollo.dev/federation", "Scope"),
3030
resolveName("https://specs.apollo.dev/join", "DirectiveArguments"),
31+
resolveName("https://specs.apollo.dev/join", "ContextArgument"),
32+
resolveName("https://specs.apollo.dev/join", "FieldValue"),
3133
]);
3234

3335
// we retrieve the list of reachable types from the public api sdl

0 commit comments

Comments
 (0)