...
1 package parser
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 "github.com/vektah/gqlparser/v2/gqlerror"
8
9 "github.com/vektah/gqlparser/v2/ast"
10 "github.com/vektah/gqlparser/v2/parser/testrunner"
11 )
12
13 func TestSchemaDocument(t *testing.T) {
14 testrunner.Test(t, "schema_test.yml", func(t *testing.T, input string) testrunner.Spec {
15 doc, err := ParseSchema(&ast.Source{Input: input, Name: "spec"})
16 if err != nil {
17 return testrunner.Spec{
18 Error: err.(*gqlerror.Error),
19 AST: ast.Dump(doc),
20 }
21 }
22 return testrunner.Spec{
23 AST: ast.Dump(doc),
24 }
25 })
26 }
27
28 func TestTypePosition(t *testing.T) {
29 t.Run("type line number with no bang", func(t *testing.T) {
30 schema, parseErr := ParseSchema(&ast.Source{
31 Input: `type query {
32 me: User
33 }
34 `,
35 })
36 assert.Nil(t, parseErr)
37 assert.Equal(t, 2, schema.Definitions.ForName("query").Fields.ForName("me").Type.Position.Line)
38 })
39 t.Run("type line number with bang", func(t *testing.T) {
40 schema, parseErr := ParseSchema(&ast.Source{
41 Input: `type query {
42 me: User!
43 }
44 `,
45 })
46 assert.Nil(t, parseErr)
47 assert.Equal(t, 2, schema.Definitions.ForName("query").Fields.ForName("me").Type.Position.Line)
48 })
49 t.Run("type line number with comments", func(t *testing.T) {
50 schema, parseErr := ParseSchema(&ast.Source{
51 Input: `type query {
52 # comment
53 me: User
54 }
55 `,
56 })
57 assert.Nil(t, parseErr)
58 assert.Equal(t, 3, schema.Definitions.ForName("query").Fields.ForName("me").Type.Position.Line)
59 })
60 }
61
View as plain text