Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/lemon-pianos-slide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@theguild/federation-composition": patch
---

Fix 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.
```
47 changes: 47 additions & 0 deletions __tests__/contracts/add-inaccessible-to-unreachable-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,50 @@ test("Filters based on tags", async () => {
}"
`);
});

test("Inaccessible is not added on built-in Federation types ContextArgument and FieldValue", async () => {
const sdl = /* GraphQL */ `
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.9", import: ["@key"])

type Query {
me: Me
}

type Me @key(fields: "id") {
id: ID!
}
`;

let compositionResult = composeServices([
{
name: "user",
url: "https://noop.graphql-hive.com",
typeDefs: parse(sdl),
},
]);

expect(compositionResult.errors).toBe(undefined);
expect(compositionResult.supergraphSdl).not.toBe(undefined);
const { resolveImportName } = extractLinkImplementations(
parse(compositionResult.supergraphSdl!),
);

compositionResult = addInaccessibleToUnreachableTypes(
resolveImportName,
compositionResult as CompositionSuccess,
);

expect(compositionResult.supergraphSdl).to.include(
"scalar join__FieldValue\n",
);
expect(compositionResult.supergraphSdl).to.not.include(
"scalar join__FieldValue @inaccessible",
);
expect(compositionResult.supergraphSdl).to.not.include(
"input join__ContextArgument @inaccessible {",
);
expect(compositionResult.supergraphSdl).to.include(
"input join__ContextArgument {\n",
);
});
2 changes: 2 additions & 0 deletions src/contracts/add-inaccessible-to-unreachable-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const addInaccessibleToUnreachableTypes = (
resolveName("https://specs.apollo.dev/federation", "Policy"),
resolveName("https://specs.apollo.dev/federation", "Scope"),
resolveName("https://specs.apollo.dev/join", "DirectiveArguments"),
resolveName("https://specs.apollo.dev/join", "ContextArgument"),
resolveName("https://specs.apollo.dev/join", "FieldValue"),
]);

// we retrieve the list of reachable types from the public api sdl
Expand Down
Loading