forked from graphql-go/graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules_known_directives_rule_test.go
86 lines (82 loc) · 2.39 KB
/
rules_known_directives_rule_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package graphql_test
import (
"testing"
"github.com/housinganywhere/graphql"
"github.com/housinganywhere/graphql/gqlerrors"
"github.com/housinganywhere/graphql/testutil"
)
func TestValidate_KnownDirectives_WithNoDirectives(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownDirectivesRule, `
query Foo {
name
...Frag
}
fragment Frag on Dog {
name
}
`)
}
func TestValidate_KnownDirectives_WithKnownDirective(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownDirectivesRule, `
{
dog @include(if: true) {
name
}
human @skip(if: false) {
name
}
}
`)
}
func TestValidate_KnownDirectives_WithUnknownDirective(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownDirectivesRule, `
{
dog @unknown(directive: "value") {
name
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown directive "unknown".`, 3, 13),
})
}
func TestValidate_KnownDirectives_WithManyUnknownDirectives(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownDirectivesRule, `
{
dog @unknown(directive: "value") {
name
}
human @unknown(directive: "value") {
name
pets @unknown(directive: "value") {
name
}
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown directive "unknown".`, 3, 13),
testutil.RuleError(`Unknown directive "unknown".`, 6, 15),
testutil.RuleError(`Unknown directive "unknown".`, 8, 16),
})
}
func TestValidate_KnownDirectives_WithWellPlacedDirectives(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownDirectivesRule, `
query Foo {
name @include(if: true)
...Frag @include(if: true)
skippedField @skip(if: true)
...SkippedFrag @skip(if: true)
}
`)
}
func TestValidate_KnownDirectives_WithMisplacedDirectives(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownDirectivesRule, `
query Foo @include(if: true) {
name @operationOnly
...Frag @operationOnly
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Directive "include" may not be used on QUERY.`, 2, 17),
testutil.RuleError(`Directive "operationOnly" may not be used on FIELD.`, 3, 14),
testutil.RuleError(`Directive "operationOnly" may not be used on FRAGMENT_SPREAD.`, 4, 17),
})
}