Skip to content

Commit

Permalink
Disallow empty parens (#292). (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchenshi authored Apr 5, 2024
1 parent 591c98b commit 59e3c3a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
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
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}

0 comments on commit 59e3c3a

Please sign in to comment.