-
Notifications
You must be signed in to change notification settings - Fork 255
feat(router): add allow_string_literals_for_enums engine option #3103
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
Merged
devsergiy
merged 1 commit into
main
from
sergiy/router-585-graphql-string-to-enum-type-mismatch-after-upgrade
Jul 22, 2026
Merged
Changes from all commits
Commits
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| --- | ||
| title: "String Literals for Enums" | ||
| icon: "quotes" | ||
| description: "Accept string literals for enum values as an opt-in deviation from the GraphQL specification." | ||
| --- | ||
|
|
||
| The GraphQL specification distinguishes between enum literals and string literals in an operation document. An enum argument accepts the enum literal `VALUE1`, but not the string literal `"VALUE1"`. By default, the router rejects a string literal used for an enum type with a validation error: | ||
|
|
||
| ``` | ||
| Enum "SomeEnum" cannot represent non-enum value: "VALUE1". | ||
| ``` | ||
|
|
||
| The `allow_string_literals_for_enums` option accepts such string literals when the string content matches one of the enum's values. Strings that do not match a value are still rejected: | ||
|
|
||
| ``` | ||
| Value "NOPE" does not exist in "SomeEnum" enum. | ||
| ``` | ||
|
|
||
| <Warning> | ||
| This is a deviation from the GraphQL specification. Servers built on graphql-js reject string literals for enums. Prefer fixing clients to send enum literals. Use this option to keep existing clients working while they migrate. | ||
| </Warning> | ||
|
|
||
| ## Examples | ||
|
|
||
| Given the schema: | ||
|
|
||
| ```graphql | ||
| enum SomeEnum { | ||
| VALUE1 | ||
| VALUE2 | ||
| } | ||
|
|
||
| type Query { | ||
| field(arg: SomeEnum): String | ||
| } | ||
| ``` | ||
|
|
||
| The following queries behave as listed: | ||
|
|
||
| ```graphql | ||
| { field(arg: VALUE1) } # Valid. Enum literal. | ||
| { field(arg: "VALUE1") } # Invalid by default. Valid with this option enabled. | ||
| { field(arg: "NOPE") } # Invalid. "NOPE" is not a value of SomeEnum. | ||
| ``` | ||
|
|
||
| Variables are not affected by this option. JSON has no enum type, so a string is the standard representation for an enum variable value and is always accepted when it matches an enum value: | ||
|
|
||
| ```graphql | ||
| query ($arg: SomeEnum) { field(arg: $arg) } | ||
| # variables: {"arg": "VALUE1"} is valid with or without this option | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| <Tabs> | ||
| <Tab title="Environment Variable"> | ||
| ```bash | ||
| ENGINE_ALLOW_STRING_LITERALS_FOR_ENUMS=true | ||
| ``` | ||
| </Tab> | ||
| <Tab title="YAML"> | ||
| ```yaml config.yaml | ||
| version: "1" | ||
|
|
||
| engine: | ||
| allow_string_literals_for_enums: true | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| This option is disabled by default. See the [Router Configuration reference](/router/configuration#router-engine-configuration) for all engine flags. |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.