-
Notifications
You must be signed in to change notification settings - Fork 9
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
Adds Enum Type Default Value Uses Inaccessible Value Rule #47
Merged
michaelstaib
merged 10 commits into
main
from
mst/EnumTypeDefaultValueUsesInaccessibleValue
Nov 14, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
47324d0
Adds Enum Type Default Value Uses Inaccessible Value Rule
michaelstaib ac86702
Update spec/Section 4 -- Composition.md
michaelstaib b7fbed8
Update spec/Section 4 -- Composition.md
michaelstaib 1ea97bb
Update spec/Section 4 -- Composition.md
michaelstaib 9b09474
Update spec/Section 4 -- Composition.md
michaelstaib 7428ffd
Update spec/Section 4 -- Composition.md
michaelstaib 6d9307b
Update spec/Section 4 -- Composition.md
michaelstaib c5d1324
Update spec/Section 4 -- Composition.md
michaelstaib 0c7240b
Merged Validation
michaelstaib 7da6d59
Formatting
michaelstaib File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,114 @@ run in sequence to produce the composite execution schema. | |
|
||
### Pre Merge Validation | ||
|
||
#### Enum Type Default Value Uses Inaccessible Value | ||
|
||
**Error Code** | ||
|
||
`ENUM_TYPE_DEFAULT_VALUE_INACCESSIBLE` | ||
|
||
**Formal Specification** | ||
|
||
- {ValidateArgumentDefaultValues()} must be true. | ||
- {ValidateInputFieldDefaultValues()} must be true. | ||
|
||
ValidateArgumentDefaultValues(): | ||
|
||
- Let {arguments} be all arguments of fields and directives across all source | ||
schemas | ||
- For each {argument} in {arguments} | ||
- If {IsExposed(argument)} is true and has a default value: | ||
- Let {defaultValue} be the default value of {argument} | ||
- If not {ValidateDefaultValue(defaultValue)} | ||
- return false | ||
- return true | ||
|
||
ValidateInputFieldDefaultValues(): | ||
|
||
- Let {inputFields} be all input fields across all source schemas | ||
- For each {inputField} in {inputFields}: | ||
- Let {type} be the type of {inputField} | ||
- If {IsExposed(inputField)} is true and {inputField} has a default value: | ||
- Let {defaultValue} be the default value of {inputField} | ||
- If {ValidateDefaultValue(defaultValue)} is false | ||
- return false | ||
- return true | ||
|
||
ValidateDefaultValue(defaultValue): | ||
|
||
- If {defaultValue} is a ListValue: | ||
- For each {valueNode} in {defaultValue}: | ||
- If {ValidateDefaultValue(valueNode)} is false | ||
- return false | ||
- If {defaultValue} is an ObjectValue: | ||
- Let {objectFields} be a list of all fields of {defaultValue} | ||
- Let {fields} be a list of all fields {objectFields} are referring to | ||
- For each {field} in {fields}: | ||
- If {IsExposed(field)} is false | ||
- return false | ||
- For each {objectField} in {objectFields}: | ||
- Let {value} be the value of {objectField} | ||
- return {ValidateDefaultValue(value)} | ||
- If {defaultValue} is an EnumValue: | ||
- If {IsExposed(defaultValue)} is false | ||
- return false | ||
- return true | ||
|
||
**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. | ||
|
||
In this example the `FOO` value in the `Enum1` enum is not marked with | ||
`@inaccessible`, hence it does not violate the rule. | ||
|
||
```graphql | ||
type Query { | ||
field(type: Enum1 = FOO): [Baz!]! | ||
} | ||
|
||
enum Enum1 { | ||
FOO | ||
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`. | ||
|
||
```graphql counter-example | ||
type Query { | ||
field(arg: Enum1 = FOO): [Baz!]! | ||
} | ||
|
||
input Input1 { | ||
field: Enum1 = FOO | ||
} | ||
|
||
directive @directive1(arg: Enum1 = FOO) on FIELD_DEFINITION | ||
|
||
enum Enum1 { | ||
FOO @inaccessible | ||
BAR | ||
} | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing description of counter-example. |
||
```graphql counter-example | ||
type Query { | ||
field(arg: Input1 = { field2: "ERROR" }): [Baz!]! | ||
} | ||
|
||
directive @directive1(arg: Input1 = { field2: "ERROR" }) on FIELD_DEFINITION | ||
|
||
input Input1 { | ||
field1: String | ||
field2: String @inaccessible | ||
} | ||
``` | ||
|
||
#### Output Field Types Mergeable | ||
|
||
**Error Code** | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be removed or described? It's not part of the example description above, and also not in the "good" example.
(same in the next counter-example)