gqlparser
gqlparser copied to clipboard
Type's line number always off by one if it includes a bang
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/vektah/gqlparser/v2/ast"
"github.com/vektah/gqlparser/v2/parser"
)
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)
})
}
The second test fails and gives an actual of 3. Seems like it just happens when the type has a bang.
Huh! Weird! I would love a pull request to fix this.