Skip to content
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 empty parens (#292). #293

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions parser/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (p *parser) parseOperationType() Operation {

func (p *parser) parseVariableDefinitions() VariableDefinitionList {
var defs []*VariableDefinition
p.many(lexer.ParenL, lexer.ParenR, func() {
p.some(lexer.ParenL, lexer.ParenR, func() {
defs = append(defs, p.parseVariableDefinition())
})

Expand Down Expand Up @@ -167,7 +167,7 @@ func (p *parser) parseField() *Field {

func (p *parser) parseArguments(isConst bool) ArgumentList {
var arguments ArgumentList
p.many(lexer.ParenL, lexer.ParenR, func() {
p.some(lexer.ParenL, lexer.ParenR, func() {
arguments = append(arguments, p.parseArgument(isConst))
})

Expand Down
9 changes: 9 additions & 0 deletions validator/schema_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ object types:
message: 'Name "__id" must not begin with "__", which is reserved by GraphQL introspection.'
locations: [{line: 2, column: 3}]

- name: field argument list must not be empty
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test merely documents the existing behavior, which is already correct (spec compliant). It's just for additional test coverage. The other two tests are for the fixes in this PR.

input: |
type FooBar {
foo(): ID
}
error:
message: 'expected at least one definition, found )'
locations: [{line: 2, column: 7}]

- name: check reserved names on type field argument
input: |
type FooBar {
Expand Down
26 changes: 26 additions & 0 deletions validator/spec/EmptyParens.spec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
- name: Empty variables list
schema: 0
query: |
query foo(){
dog {
__typename
}
}

errors:
- message: "expected at least one definition, found )"
locations:
- {line: 1, column: 11}
- name: Empty arguments list
schema: 0
query: |
query foo{
dog() {
__typename
}
}

errors:
- message: "expected at least one definition, found )"
locations:
- {line: 2, column: 7}
Loading