Skip to content

Commit

Permalink
relax rules for inaccessible
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Jan 26, 2024
1 parent 98b90c9 commit 3d6ca58
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-pants-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@theguild/federation-composition': patch
---

Fix REQUIRED_INACCESSIBLE occurring on inaccessible fields/input types
49 changes: 45 additions & 4 deletions __tests__/supergraph/errors/REQUIRED_INACCESSIBLE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ testVersions((api, version) => {
url: "https://specs.apollo.dev/federation/${version}"
import: ["@key", "@inaccessible"]
)
type Query {
a(id: ID! @inaccessible): Int!
}
Expand All @@ -33,7 +32,6 @@ testVersions((api, version) => {
]),
}),
);

expect(
api.composeServices([
{
Expand All @@ -44,12 +42,11 @@ testVersions((api, version) => {
url: "https://specs.apollo.dev/federation/${version}"
import: ["@key", "@inaccessible"]
)
input A {
id: ID! @inaccessible
b: Int
}
type Query {
a(a: A): Int!
}
Expand All @@ -69,5 +66,49 @@ testVersions((api, version) => {
]),
}),
);

expect(
api.composeServices([
{
name: 'users',
typeDefs: graphql`
extend schema
@link(
url: "https://specs.apollo.dev/federation/${version}"
import: ["@inaccessible"]
)
type Query {
a(id: ID! @inaccessible): Int!@inaccessible
b: Int!
}
`,
},
])?.errors,
).toBeUndefined();

expect(
api.composeServices([
{
name: 'users',
typeDefs: graphql`
extend schema
@link(
url: "https://specs.apollo.dev/federation/${version}"
import: ["@inaccessible"]
)
input A @inaccessible {
a: Int! @inaccessible
}
type Query {
a(id: A! @inaccessible): Int! @inaccessible
b: Int!
}
`,
},
])?.errors,
).toBeUndefined();
});
});
2 changes: 2 additions & 0 deletions src/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ ${print({
export type CompositionResult = CompositionFailure | CompositionSuccess;

export interface CompositionFailure {
supergraphSdl?: undefined;
errors: GraphQLError[];
}

export interface CompositionSuccess {
supergraphSdl: string;
errors?: undefined;
}

export function assertCompositionSuccess(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export function RequiredArgumentOrFieldIsNotInaccessibleRule(
): SupergraphVisitorMap {
return {
InputObjectTypeField(inputObjectState, fieldState) {
if (fieldState.type.endsWith('!') && fieldState.inaccessible) {
if (
!inputObjectState.inaccessible &&
fieldState.inaccessible &&
fieldState.type.endsWith('!')
) {
context.reportError(
new GraphQLError(
`Input field "${inputObjectState.name}.${fieldState.name}" is @inaccessible but is a required input field of its type.`,
Expand All @@ -21,7 +25,7 @@ export function RequiredArgumentOrFieldIsNotInaccessibleRule(
}
},
ObjectTypeFieldArg(objectState, fieldState, argState) {
if (argState.type.endsWith('!') && argState.inaccessible) {
if (!fieldState.inaccessible && argState.inaccessible && argState.type.endsWith('!')) {
context.reportError(
new GraphQLError(
`Argument "${objectState.name}.${fieldState.name}(${argState.name}:)" is @inaccessible but is a required argument of its field.`,
Expand Down

0 comments on commit 3d6ca58

Please sign in to comment.