Skip to content

Commit 5171007

Browse files
authored
Update validation rule "Enum Type Default Value Inaccessible" (#182)
1 parent d414450 commit 5171007

1 file changed

Lines changed: 44 additions & 19 deletions

File tree

spec/Section 4 -- Composition.md

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5495,7 +5495,7 @@ enum DeliveryStatus {
54955495
}
54965496
```
54975497

5498-
#### Enum Type Default Value Uses Inaccessible Value
5498+
#### Enum Type Default Value Inaccessible
54995499

55005500
**Error Code**
55015501

@@ -5508,8 +5508,7 @@ enum DeliveryStatus {
55085508

55095509
ValidateArgumentDefaultValues():
55105510

5511-
- Let {arguments} be the set of all arguments of fields and directives the
5512-
composed schema
5511+
- Let {arguments} be the set of all arguments of fields in the composed schema
55135512
- For each {argument} in {arguments}
55145513
- If {argument} has a default value:
55155514
- Let {defaultValue} be the default value of {argument}
@@ -5537,7 +5536,8 @@ ValidateDefaultValue(defaultValue):
55375536
- Let {objectFields} be a list of all fields of {defaultValue}
55385537
- For each {objectField} in {objectFields}:
55395538
- Let {value} be the value of {objectField}
5540-
- return {ValidateDefaultValue(value)}
5539+
- If {ValidateDefaultValue(value)} is false
5540+
- return false
55415541
- If {defaultValue} is an EnumValue:
55425542
- If {enum} be the enum type of {defaultValue}
55435543
- If {enum} does not have a value with the name of {defaultValue}
@@ -5547,9 +5547,9 @@ ValidateDefaultValue(defaultValue):
55475547
**Explanatory Text**
55485548

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

55545554
In this example the `FOO` value in the `Enum1` enum is not marked with
55555555
`@inaccessible`, hence it does not violate the rule.
@@ -5566,9 +5566,9 @@ enum Enum1 {
55665566
}
55675567
```
55685568

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

55735573
```graphql counter-example
55745574
# Schema A
@@ -5580,29 +5580,54 @@ input Input1 {
55805580
field: Enum1 = FOO
55815581
}
55825582

5583-
directive @directive1(arg: Enum1 = FOO) on FIELD_DEFINITION
5584-
55855583
enum Enum1 {
55865584
FOO @inaccessible
55875585
BAR
55885586
}
55895587
```
55905588

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

55955593
```graphql counter-example
55965594
# Schema A
55975595
type Query {
5598-
field(arg: Input1 = { field2: "ERROR" }): [Baz!]!
5596+
field(arg: Input1 = { field1: FOO }): [Baz!]!
5597+
}
5598+
5599+
input Input1 {
5600+
field1: Enum1
5601+
field2: Input2 = { field3: FOO }
5602+
}
5603+
5604+
input Input2 {
5605+
field3: Enum1
5606+
}
5607+
5608+
enum Enum1 {
5609+
FOO @inaccessible
5610+
BAR
55995611
}
5612+
```
5613+
5614+
The following example violates this rule because the default value for the
5615+
argument (`arg`) and the input field (`field`) references an `@inaccessible`
5616+
enum value (`FOO`) within a list.
56005617

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

56035624
input Input1 {
5604-
field1: String
5605-
field2: String @inaccessible
5625+
field: [Enum1] = [FOO]
5626+
}
5627+
5628+
enum Enum1 {
5629+
FOO @inaccessible
5630+
BAR
56065631
}
56075632
```
56085633

0 commit comments

Comments
 (0)