...
1 package parser
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7
8 "github.com/vektah/gqlparser/v2/ast"
9 "github.com/vektah/gqlparser/v2/gqlerror"
10 "github.com/vektah/gqlparser/v2/parser/testrunner"
11 )
12
13 func TestQueryDocument(t *testing.T) {
14 testrunner.Test(t, "query_test.yml", func(t *testing.T, input string) testrunner.Spec {
15 doc, err := ParseQuery(&ast.Source{Input: input, Name: "spec"})
16 if err != nil {
17 gqlErr := err.(*gqlerror.Error)
18 return testrunner.Spec{
19 Error: gqlErr,
20 AST: ast.Dump(doc),
21 }
22 }
23 return testrunner.Spec{
24 AST: ast.Dump(doc),
25 }
26 })
27 }
28
29 func TestQueryPosition(t *testing.T) {
30 t.Run("query line number with comments", func(t *testing.T) {
31 query, err := ParseQuery(&ast.Source{
32 Input: `
33 # comment 1
34 query SomeOperation {
35 # comment 2
36 myAction {
37 id
38 }
39 }
40 `,
41 })
42 assert.Nil(t, err)
43 assert.Equal(t, 3, query.Operations.ForName("SomeOperation").Position.Line)
44 assert.Equal(t, 5, query.Operations.ForName("SomeOperation").SelectionSet[0].GetPosition().Line)
45 })
46 }
47
View as plain text