forked from graphql-go/graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules_unique_operation_names_test.go
104 lines (97 loc) · 2.58 KB
/
rules_unique_operation_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
package graphql_test
import (
"testing"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/gqlerrors"
"github.com/graphql-go/graphql/testutil"
)
func TestValidate_UniqueOperationNames_NoOperations(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueOperationNamesRule, `
fragment fragA on Type {
field
}
`)
}
func TestValidate_UniqueOperationNames_OneAnonOperation(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueOperationNamesRule, `
{
field
}
`)
}
func TestValidate_UniqueOperationNames_OneNamedOperation(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueOperationNamesRule, `
query Foo {
field
}
`)
}
func TestValidate_UniqueOperationNames_MultipleOperations(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueOperationNamesRule, `
query Foo {
field
}
query Bar {
field
}
`)
}
func TestValidate_UniqueOperationNames_MultipleOperationsOfDifferentTypes(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueOperationNamesRule, `
query Foo {
field
}
mutation Bar {
field
}
subscription Baz {
field
}
`)
}
func TestValidate_UniqueOperationNames_FragmentAndOperationNamedTheSame(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueOperationNamesRule, `
query Foo {
...Foo
}
fragment Foo on Type {
field
}
`)
}
func TestValidate_UniqueOperationNames_MultipleOperationsOfSameName(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.UniqueOperationNamesRule, `
query Foo {
fieldA
}
query Foo {
fieldB
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`There can only be one operation named "Foo".`, 2, 13, 5, 13),
})
}
func TestValidate_UniqueOperationNames_MultipleOperationsOfSameNameOfDifferentTypes_Mutation(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.UniqueOperationNamesRule, `
query Foo {
fieldA
}
mutation Foo {
fieldB
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`There can only be one operation named "Foo".`, 2, 13, 5, 16),
})
}
func TestValidate_UniqueOperationNames_MultipleOperationsOfSameNameOfDifferentTypes_Subscription(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.UniqueOperationNamesRule, `
query Foo {
fieldA
}
subscription Foo {
fieldB
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`There can only be one operation named "Foo".`, 2, 13, 5, 20),
})
}