Skip to content

Commit

Permalink
fix: ignore inaccessible field argument for DEFAULT_VALUE_USES_INACCE…
Browse files Browse the repository at this point in the history
…SSIBLE rule (#39)

Ignore inaccessible field arguments within the
`DEFAULT_VALUE_USES_INACCESSIBLE` rule.

Fixes an issue where an inaccessible field argument uses a default value
that is inaccessible would
cause a false error.

```graphql
type User @key(fields: "id") {
  id: ID
  friends(type: FriendType = FAMILY @inaccessible): [User!]!
}

enum FriendType {
  FAMILY @inaccessible
  FRIEND
}
```
  • Loading branch information
n1ru4l authored Jan 8, 2024
1 parent 220dfc0 commit e77eb2c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .changeset/sharp-trees-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@theguild/federation-composition': patch
---

Ignore inaccessible field arguments within the `DEFAULT_VALUE_USES_INACCESSIBLE` rule.

Fixes an issue where an inaccessible field argument uses a default value that is inaccessible would
cause a false error.

```graphql
type User @key(fields: "id") {
id: ID
friends(type: FriendType = FAMILY @inaccessible): [User!]!
}

enum FriendType {
FAMILY @inaccessible
FRIEND
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,34 @@ testVersions((api, version) => {
]),
}),
);

expect(
api.composeServices([
{
name: 'users',
typeDefs: graphql`
extend schema
@link(
url: "https://specs.apollo.dev/federation/${version}"
import: ["@key", "@inaccessible"]
)
type Query {
users: [User!]!
}
type User @key(fields: "id") {
id: ID
friends(type: FriendType = FAMILY @inaccessible): [User!]!
}
enum FriendType {
FAMILY @inaccessible
FRIEND
}
`,
},
]),
).toEqual(expect.objectContaining({ supergraphSdl: expect.any(String) }));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function DefaultValueUsesInaccessibleRule(
return;
}

if (argState.inaccessible) {
return;
}

detectInaccessibleDefaultValue(
context,
() => `${objectState.name}.${fieldState.name}(${argState.name}:)`,
Expand Down

0 comments on commit e77eb2c

Please sign in to comment.