Skip to content

Commit

Permalink
Fixes #231: Parsing a field type with a bang should not increase the …
Browse files Browse the repository at this point in the history
…line number (#236)

Co-authored-by: Ahmad Moudani <ahmad.moudani@crowdstrike.com>
  • Loading branch information
zmay2030 and Ahmad Moudani committed Sep 9, 2022
1 parent 88d9590 commit eae2341
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 0 additions & 1 deletion parser/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ func (p *parser) parseTypeReference() *Type {
}

if p.skip(lexer.Bang) {
typ.Position = p.peekPos()
typ.NonNull = true
}
return &typ
Expand Down
26 changes: 25 additions & 1 deletion parser/schema_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parser

import (
"github.com/stretchr/testify/assert"
"github.com/vektah/gqlparser/v2/gqlerror"
"testing"

Expand All @@ -18,7 +19,30 @@ func TestSchemaDocument(t *testing.T) {
}
}
return testrunner.Spec{
AST: ast.Dump(doc),
AST: ast.Dump(doc),
}
})
}

func TestTypePosition(t *testing.T) {
t.Run("type line number with no bang", func(t *testing.T) {
schema, parseErr := ParseSchema(&ast.Source{
Input: `type query {
me: User
}
`,
})
assert.Nil(t, parseErr)
assert.Equal(t, 2, schema.Definitions.ForName("query").Fields.ForName("me").Type.Position.Line)
})
t.Run("type line number with bang", func(t *testing.T) {
schema, parseErr := ParseSchema(&ast.Source{
Input: `type query {
me: User!
}
`,
})
assert.Nil(t, parseErr)
assert.Equal(t, 2, schema.Definitions.ForName("query").Fields.ForName("me").Type.Position.Line)
})
}

0 comments on commit eae2341

Please sign in to comment.