forked from graphql-go/graphql
/
rules_known_type_names_test.go
61 lines (57 loc) · 1.56 KB
/
rules_known_type_names_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package graphql_test
import (
"testing"
"github.com/opsee/graphql"
"github.com/opsee/graphql/gqlerrors"
"github.com/opsee/graphql/testutil"
)
func TestValidate_KnownTypeNames_KnownTypeNamesAreValid(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownTypeNamesRule, `
query Foo($var: String, $required: [String!]!) {
user(id: 4) {
pets { ... on Pet { name }, ...PetFields, ... { name } }
}
}
fragment PetFields on Pet {
name
}
`)
}
func TestValidate_KnownTypeNames_UnknownTypeNamesAreInValid(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownTypeNamesRule, `
query Foo($var: JumbledUpLetters) {
user(id: 4) {
name
pets { ... on Badger { name }, ...PetFields }
}
}
fragment PetFields on Peettt {
name
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown type "JumbledUpLetters".`, 2, 23),
testutil.RuleError(`Unknown type "Badger".`, 5, 25),
testutil.RuleError(`Unknown type "Peettt".`, 8, 29),
})
}
func TestValidate_KnownTypeNames_IgnoresTypeDefinitions(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownTypeNamesRule, `
type NotInTheSchema {
field: FooBar
}
interface FooBar {
field: NotInTheSchema
}
union U = A | B
input Blob {
field: UnknownType
}
query Foo($var: NotInTheSchema) {
user(id: $var) {
id
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown type "NotInTheSchema".`, 12, 23),
})
}