gqlparser icon indicating copy to clipboard operation
gqlparser copied to clipboard

Type's line number always off by one if it includes a bang

Open zmay2030 opened this issue 3 years ago • 1 comments

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.

zmay2030 avatar Jul 12 '22 23:07 zmay2030

Huh! Weird! I would love a pull request to fix this.

StevenACoffman avatar Jul 13 '22 23:07 StevenACoffman