Skip to content
Open
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
19 changes: 19 additions & 0 deletions .changeset/hip-states-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"@theguild/federation-composition": patch
---

Fix `REQUIRED_INACCESSIBLE` composition rule reporting a composition error if `@inaccessible` is applied on a non-nullable field with a default value.

In the following example schema the `Query.ping(message:)` argument no longer raises `REQUIRED_INACCESSIBLE`, as a default value for the argument is provided. The same behaviour applies for input type fields.

```graphql
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.9"
import: ["@inaccessible"]
)

type Query {
ping(message: String! = "pong" @inaccessible): String!
}
```
46 changes: 45 additions & 1 deletion __tests__/supergraph/errors/REQUIRED_INACCESSIBLE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ testVersions((api, version) => {
url: "https://specs.apollo.dev/federation/${version}"
import: ["@key", "@inaccessible"]
)

input A {
id: ID! @inaccessible
b: Int
Expand Down Expand Up @@ -110,5 +110,49 @@ testVersions((api, version) => {
},
])?.errors,
).toBeUndefined();

expect(
api.composeServices([
{
name: "users",
typeDefs: graphql`
extend schema
@link(
url: "https://specs.apollo.dev/federation/${version}"
import: ["@inaccessible"]
)

type Query {
a(id: String! = "brrry" @inaccessible): Int!
}
`,
},
])?.errors,
).toBeUndefined();

expect(
api.composeServices([
{
name: "users",
typeDefs: graphql`
extend schema
@link(
url: "https://specs.apollo.dev/federation/${version}"
import: ["@inaccessible"]
)

input Foo {
a: String
b: String! = "he he he" @inaccessible
}

type Query {
a(id: Foo!): Int!
b: Int!
}
`,
},
])?.errors,
).toBeUndefined();
Comment thread
n1ru4l marked this conversation as resolved.
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export function RequiredArgumentOrFieldIsNotInaccessibleRule(
if (
!inputObjectState.inaccessible &&
fieldState.inaccessible &&
fieldState.type.endsWith("!")
fieldState.type.endsWith("!") &&
fieldState.defaultValue === undefined
) {
context.reportError(
new GraphQLError(
Expand All @@ -28,7 +29,8 @@ export function RequiredArgumentOrFieldIsNotInaccessibleRule(
if (
!fieldState.inaccessible &&
argState.inaccessible &&
argState.type.endsWith("!")
argState.type.endsWith("!") &&
argState.defaultValue === undefined
) {
context.reportError(
new GraphQLError(
Expand Down
Loading