-
Notifications
You must be signed in to change notification settings - Fork 842
/
rules_known_argument_names_test.go
135 lines (132 loc) · 4.4 KB
/
rules_known_argument_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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package graphql_test
import (
"testing"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/gqlerrors"
"github.com/graphql-go/graphql/testutil"
)
func TestValidate_KnownArgumentNames_SingleArgIsKnown(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownArgumentNamesRule, `
fragment argOnRequiredArg on Dog {
doesKnowCommand(dogCommand: SIT)
}
`)
}
func TestValidate_KnownArgumentNames_MultipleArgsAreKnown(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownArgumentNamesRule, `
fragment multipleArgs on ComplicatedArgs {
multipleReqs(req1: 1, req2: 2)
}
`)
}
func TestValidate_KnownArgumentNames_IgnoresArgsOfUnknownFields(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownArgumentNamesRule, `
fragment argOnUnknownField on Dog {
unknownField(unknownArg: SIT)
}
`)
}
func TestValidate_KnownArgumentNames_MultipleArgsInReverseOrderAreKnown(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownArgumentNamesRule, `
fragment multipleArgsReverseOrder on ComplicatedArgs {
multipleReqs(req2: 2, req1: 1)
}
`)
}
func TestValidate_KnownArgumentNames_NoArgsOnOptionalArg(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownArgumentNamesRule, `
fragment noArgOnOptionalArg on Dog {
isHousetrained
}
`)
}
func TestValidate_KnownArgumentNames_ArgsAreKnownDeeply(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownArgumentNamesRule, `
{
dog {
doesKnowCommand(dogCommand: SIT)
}
human {
pet {
... on Dog {
doesKnowCommand(dogCommand: SIT)
}
}
}
}
`)
}
func TestValidate_KnownArgumentNames_DirectiveArgsAreKnown(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownArgumentNamesRule, `
{
dog @skip(if: true)
}
`)
}
func TestValidate_KnownArgumentNames_UndirectiveArgsAreInvalid(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownArgumentNamesRule, `
{
dog @skip(unless: true)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown argument "unless" on directive "@skip".`, 3, 19),
})
}
func TestValidate_KnownArgumentNames_UndirectiveArgsAreInvalidWithSuggestion(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownArgumentNamesRule, `
{
dog @skip(of: true)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown argument "of" on directive "@skip". `+
`Did you mean "if"?`, 3, 19),
})
}
func TestValidate_KnownArgumentNames_InvalidArgName(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownArgumentNamesRule, `
fragment invalidArgName on Dog {
doesKnowCommand(unknown: true)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown argument "unknown" on field "doesKnowCommand" of type "Dog".`, 3, 25),
})
}
func TestValidate_KnownArgumentNames_UnknownArgsAmongstKnownArgs(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownArgumentNamesRule, `
fragment oneGoodArgOneInvalidArg on Dog {
doesKnowCommand(whoknows: 1, dogCommand: SIT, unknown: true)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown argument "whoknows" on field "doesKnowCommand" of type "Dog".`, 3, 25),
testutil.RuleError(`Unknown argument "unknown" on field "doesKnowCommand" of type "Dog".`, 3, 55),
})
}
func TestValidate_KnownArgumentNames_UnknownArgsAmongstKnownArgsWithSuggestions(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownArgumentNamesRule, `
fragment oneGoodArgOneInvalidArg on Dog {
doesKnowCommand(ddogCommand: SIT,)
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown argument "ddogCommand" on field "doesKnowCommand" of type "Dog". `+
`Did you mean "dogCommand" or "nextDogCommand"?`, 3, 25),
})
}
func TestValidate_KnownArgumentNames_UnknownArgsDeeply(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownArgumentNamesRule, `
{
dog {
doesKnowCommand(unknown: true)
}
human {
pet {
... on Dog {
doesKnowCommand(unknown: true)
}
}
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown argument "unknown" on field "doesKnowCommand" of type "Dog".`, 4, 27),
testutil.RuleError(`Unknown argument "unknown" on field "doesKnowCommand" of type "Dog".`, 9, 31),
})
}