Skip to content

Commit eae2341

Browse files
zmay2030Ahmad Moudani
andauthored
Fixes #231: Parsing a field type with a bang should not increase the line number (#236)
Co-authored-by: Ahmad Moudani <[email protected]>
1 parent 88d9590 commit eae2341

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

parser/query.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ func (p *parser) parseTypeReference() *Type {
336336
}
337337

338338
if p.skip(lexer.Bang) {
339-
typ.Position = p.peekPos()
340339
typ.NonNull = true
341340
}
342341
return &typ

parser/schema_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package parser
22

33
import (
4+
"github.com/stretchr/testify/assert"
45
"github.com/vektah/gqlparser/v2/gqlerror"
56
"testing"
67

@@ -18,7 +19,30 @@ func TestSchemaDocument(t *testing.T) {
1819
}
1920
}
2021
return testrunner.Spec{
21-
AST: ast.Dump(doc),
22+
AST: ast.Dump(doc),
2223
}
2324
})
2425
}
26+
27+
func TestTypePosition(t *testing.T) {
28+
t.Run("type line number with no bang", func(t *testing.T) {
29+
schema, parseErr := ParseSchema(&ast.Source{
30+
Input: `type query {
31+
me: User
32+
}
33+
`,
34+
})
35+
assert.Nil(t, parseErr)
36+
assert.Equal(t, 2, schema.Definitions.ForName("query").Fields.ForName("me").Type.Position.Line)
37+
})
38+
t.Run("type line number with bang", func(t *testing.T) {
39+
schema, parseErr := ParseSchema(&ast.Source{
40+
Input: `type query {
41+
me: User!
42+
}
43+
`,
44+
})
45+
assert.Nil(t, parseErr)
46+
assert.Equal(t, 2, schema.Definitions.ForName("query").Fields.ForName("me").Type.Position.Line)
47+
})
48+
}

0 commit comments

Comments
 (0)