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

Line numbers are wrong for the schema with multiline description #229

Closed
schafle opened this issue Jul 6, 2022 · 3 comments
Closed

Line numbers are wrong for the schema with multiline description #229

schafle opened this issue Jul 6, 2022 · 3 comments

Comments

@schafle
Copy link
Contributor

schafle commented Jul 6, 2022

Schema parsed by gqlparser does not consider newlines in the multiline descriptions and thus line numbers are off if there are multi-line descriptions present in the schema.

Code to reproduce the issue

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 without description", func(t *testing.T) {
		schema, parseErr := parser.ParseSchema(&ast.Source{
			Input: `type User {
  				name: String!
			}
			type query {
  				me: User!
			}
			`,
		})
		assert.Nil(t, parseErr)
		assert.Equal(t, schema.Definitions.ForName("query").Position.Line, 4)
	})
	t.Run("schema with single line description", func(t *testing.T) {
		schema, parseErr := parser.ParseSchema(&ast.Source{
			Input: `type User {
  				name: String!
			}
			"""some description"""
			type query {
  				me: User!
			}
			`,
		})
		assert.Nil(t, parseErr)
		assert.Equal(t, schema.Definitions.ForName("query").Position.Line, 5)
	})
	t.Run("schema with multi-line description", func(t *testing.T) {
		schema, parseErr := parser.ParseSchema(&ast.Source{
			Input: `type User {
  				name: String!
			}
			"""
				some 
				description
			"""
			type query {
  				me: User!
			}
			`,
		})
		assert.Nil(t, parseErr)
		assert.Equal(t, schema.Definitions.ForName("query").Position.Line, 8)
	})
}

Test schema with multi-line description should not fail.

@StevenACoffman
Copy link
Collaborator

Oh gosh, thank you! I would really appreciate a PR to contribute those test cases as well as a fix.

zmay2030 pushed a commit to zmay2030/gqlparser that referenced this issue Jul 12, 2022
@zmay2030 zmay2030 mentioned this issue Jul 12, 2022
@schafle
Copy link
Contributor Author

schafle commented Jul 20, 2022

@StevenACoffman PR #230 fixes the issue. Can you take a look?

@StevenACoffman
Copy link
Collaborator

Thanks! Sorry I was out of town.

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