Skip to content

Update validation rule "Enum Type Default Value Inaccessible" #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
63 changes: 44 additions & 19 deletions spec/Section 4 -- Composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -5494,7 +5494,7 @@ enum DeliveryStatus {
}
```

#### Enum Type Default Value Uses Inaccessible Value
#### Enum Type Default Value Inaccessible

**Error Code**

Expand All @@ -5507,8 +5507,7 @@ enum DeliveryStatus {

ValidateArgumentDefaultValues():

- Let {arguments} be the set of all arguments of fields and directives the
composed schema
- Let {arguments} be the set of all arguments of fields in the composed schema
- For each {argument} in {arguments}
- If {argument} has a default value:
- Let {defaultValue} be the default value of {argument}
Expand Down Expand Up @@ -5536,7 +5535,8 @@ ValidateDefaultValue(defaultValue):
- Let {objectFields} be a list of all fields of {defaultValue}
- For each {objectField} in {objectFields}:
- Let {value} be the value of {objectField}
- return {ValidateDefaultValue(value)}
- If {ValidateDefaultValue(value)} is false
- return false
- If {defaultValue} is an EnumValue:
- If {enum} be the enum type of {defaultValue}
- If {enum} does not have a value with the name of {defaultValue}
Expand All @@ -5546,9 +5546,9 @@ ValidateDefaultValue(defaultValue):
**Explanatory Text**

This rule ensures that inaccessible enum values are not exposed in the composed
schema through default values. Output field arguments, input fields, and
directive arguments must only use enum values as their default value when not
annotated with the `@inaccessible` directive.
schema through default values. Output field arguments and input fields must only
use enum values as their default value when not annotated with the
`@inaccessible` directive.

In this example the `FOO` value in the `Enum1` enum is not marked with
`@inaccessible`, hence it does not violate the rule.
Expand All @@ -5565,9 +5565,9 @@ enum Enum1 {
}
```

The following example violates this rule because the default value for the field
`field` in type `Input1` references an enum value (`FOO`) that is marked as
`@inaccessible`.
The following example violates this rule because the default value for the
argument (`arg`) and the input field (`field`) references an enum value (`FOO`)
that is marked as `@inaccessible`.

```graphql counter-example
# Schema A
Expand All @@ -5579,29 +5579,54 @@ input Input1 {
field: Enum1 = FOO
}

directive @directive1(arg: Enum1 = FOO) on FIELD_DEFINITION

enum Enum1 {
FOO @inaccessible
BAR
}
```

The following example violates this rule because the default value for the field
`field` in type `Input1` references an enum value (`FOO`) that is marked as
`@inaccessible`.
The following example violates this rule because the default value for the
argument (`arg`) and the input field (`field2`) references an `@inaccessible`
enum value (`FOO`) within an object value.

```graphql counter-example
# Schema A
type Query {
field(arg: Input1 = { field2: "ERROR" }): [Baz!]!
field(arg: Input1 = { field1: FOO }): [Baz!]!
}

input Input1 {
field1: Enum1
field2: Input2 = { field3: FOO }
}

input Input2 {
field3: Enum1
}

enum Enum1 {
FOO @inaccessible
BAR
}
```

The following example violates this rule because the default value for the
argument (`arg`) and the input field (`field`) references an `@inaccessible`
enum value (`FOO`) within a list.

directive @directive1(arg: Input1 = { field2: "ERROR" }) on FIELD_DEFINITION
```graphql counter-example
# Schema A
type Query {
field(arg: [Enum1] = [FOO]): [Baz!]!
}

input Input1 {
field1: String
field2: String @inaccessible
field: [Enum1] = [FOO]
}

enum Enum1 {
FOO @inaccessible
BAR
}
```

Expand Down