Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Columns are negative for fields with multi-line comments #254

Open
andrejgou opened this issue Feb 14, 2023 · 1 comment
Open

Columns are negative for fields with multi-line comments #254

andrejgou opened this issue Feb 14, 2023 · 1 comment

Comments

@andrejgou
Copy link

andrejgou commented Feb 14, 2023

What happened?

Columns are negative for fields with multi-line comments.
The below test fails with the following errors:

Error:      	Not equal: 
               	expected: 8
            	actual  : -8
Test:       	TestSchemaParser/schema_with_multi-line_description
Messages:   	wrong column for 'me'

and

Error:      	Not equal: 
               	expected: 8
               	actual  : -9
Test:       	TestSchemaParser/schema_with_multi-line_description
Messages:   	wrong column for 'name'
package main

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/vektah/gqlparser/v2/ast"
	"github.com/vektah/gqlparser/v2/parser"
)

func TestSchemaParser(t *testing.T) {
	t.Run("schema with multi-line description", func(t *testing.T) {
		schema, parseErr := parser.ParseSchema(&ast.Source{
			Input: `type User {
				"""
				name
				"""
  				name: String!
			}
			"""
				some 
				description
			"""
			type query {
				""" 
				me
				"""
  				me: User!
			}
			`,
		})
		assert.Nil(t, parseErr)
		queryType := schema.Definitions.ForName("query")
		for _, field := range queryType.Fields {
			assert.Equal(t, "me", field.Name)
			assert.Equal(t, 14, field.Position.Line)
			assert.Equal(t, 8, field.Position.Column, "wrong column for 'me'")
		}
		assert.Equal(t, 11, queryType.Position.Line)
		assert.Equal(t, 9, queryType.Position.Column)
		userType := schema.Definitions.ForName("User")
		for _, field := range userType.Fields {
			assert.Equal(t, "name", field.Name)
			assert.Equal(t, 4, field.Position.Line)
			assert.Equal(t, 8, field.Position.Column, "wrong column for 'name'")
		}
		assert.Equal(t, 1, userType.Position.Line)
		assert.Equal(t, 6, userType.Position.Column)
	})
}

What did you expect?

Columns should not be negative for fields with multiline comments

Minimal graphql.schema and models to reproduce

See above test case

versions

  • go list -m github.com/vektah/gqlparser/v2? v2.4.7
  • go version? go1.19.3

No error occurs on v2.4.6, so I suspect it was introduced in this PR: #230

@StevenACoffman
Copy link
Collaborator

Hi! A PR that fixes this without regressing the original problem would be welcome. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants