Skip to content

Commit c417891

Browse files
authored
fix: REQUIRED_INACCESSIBLE with default values (#299)
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! } ```
1 parent 7d60ab9 commit c417891

3 files changed

Lines changed: 68 additions & 3 deletions

File tree

.changeset/hip-states-agree.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
"@theguild/federation-composition": patch
3+
---
4+
5+
Fix `REQUIRED_INACCESSIBLE` composition rule reporting a composition error if `@inaccessible` is applied on a non-nullable field with a default value.
6+
7+
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.
8+
9+
```graphql
10+
extend schema
11+
@link(
12+
url: "https://specs.apollo.dev/federation/v2.9"
13+
import: ["@inaccessible"]
14+
)
15+
16+
type Query {
17+
ping(message: String! = "pong" @inaccessible): String!
18+
}
19+
```

__tests__/supergraph/errors/REQUIRED_INACCESSIBLE.spec.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ testVersions((api, version) => {
4242
url: "https://specs.apollo.dev/federation/${version}"
4343
import: ["@key", "@inaccessible"]
4444
)
45-
45+
4646
input A {
4747
id: ID! @inaccessible
4848
b: Int
@@ -110,5 +110,49 @@ testVersions((api, version) => {
110110
},
111111
])?.errors,
112112
).toBeUndefined();
113+
114+
expect(
115+
api.composeServices([
116+
{
117+
name: "users",
118+
typeDefs: graphql`
119+
extend schema
120+
@link(
121+
url: "https://specs.apollo.dev/federation/${version}"
122+
import: ["@inaccessible"]
123+
)
124+
125+
type Query {
126+
a(id: String! = "brrry" @inaccessible): Int!
127+
}
128+
`,
129+
},
130+
])?.errors,
131+
).toBeUndefined();
132+
133+
expect(
134+
api.composeServices([
135+
{
136+
name: "users",
137+
typeDefs: graphql`
138+
extend schema
139+
@link(
140+
url: "https://specs.apollo.dev/federation/${version}"
141+
import: ["@inaccessible"]
142+
)
143+
144+
input Foo {
145+
a: String
146+
b: String! = "he he he" @inaccessible
147+
}
148+
149+
type Query {
150+
a(id: Foo!): Int!
151+
b: Int!
152+
}
153+
`,
154+
},
155+
])?.errors,
156+
).toBeUndefined();
113157
});
114158
});

src/supergraph/validation/rules/required-argument-or-field-is-not-inaccessible-rule.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export function RequiredArgumentOrFieldIsNotInaccessibleRule(
1010
if (
1111
!inputObjectState.inaccessible &&
1212
fieldState.inaccessible &&
13-
fieldState.type.endsWith("!")
13+
fieldState.type.endsWith("!") &&
14+
fieldState.defaultValue === undefined
1415
) {
1516
context.reportError(
1617
new GraphQLError(
@@ -28,7 +29,8 @@ export function RequiredArgumentOrFieldIsNotInaccessibleRule(
2829
if (
2930
!fieldState.inaccessible &&
3031
argState.inaccessible &&
31-
argState.type.endsWith("!")
32+
argState.type.endsWith("!") &&
33+
argState.defaultValue === undefined
3234
) {
3335
context.reportError(
3436
new GraphQLError(

0 commit comments

Comments
 (0)