-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Disallow "true", "false", and "null" as enum values #3223
Disallow "true", "false", and "null" as enum values #3223
Conversation
|
c01d402
to
aa52fdb
Compare
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.
@Yogu Thanks for the change 👍
Can you please make it more in line with what we already have for restricting fragment names:
graphql-js/src/language/parser.ts
Lines 498 to 506 in 6a5f51f
/** | |
* FragmentName : Name but not `on` | |
*/ | |
parseFragmentName(): NameNode { | |
if (this._lexer.token.value === 'on') { | |
throw this.unexpected(); | |
} | |
return this.parseName(); | |
} |
No need for custom AST node type just apple restriction during parsing.
But please keep your custom error message, since it improves DX a lot.
It isn't a "custom" AST node type. |
aa52fdb
to
51ac1c1
Compare
4e44107
to
fc88bd4
Compare
/** | ||
* EnumValue : Name but not `true`, `false` or `null` | ||
*/ | ||
parseEnumValueName(): NameNode { |
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.
renamed this to parseEnumValueName()
because it's no longer parsing into an EnumValue
. but still having it in its own function keeps things clean.
The specification disallows these in the SDL grammar definition, and using one of these enum values would result in a schema that would throw validation errors on creation. Fixes graphql#3221.
fc88bd4
to
36f2edb
Compare
I checked the spec and you are completely right 👍
I think it's would be surprising behaviors, e.g. you wrote your visitor for But I agree that this creates a mismatch with the spec. |
this._lexer.token.start, | ||
`${getTokenDesc( | ||
this._lexer.token, | ||
)} is reserved and cannot be used for an enum value.`, |
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.
BTW. Adding a similar message to fragment name parsing is welcomed if you want to work on such PR.
The specification disallows these in the SDL grammar definition, and using one of these enum values would result in a schema that would throw validation errors on creation.
Fixes #3221.
I also changed the type of
EnumValueDefinitionNode.name
fromNameNode
toEnumValueNode
, so this is definitely breaking. We might even want to rename thename
property tovalue
, but that would be even more breaking.