forked from graphql-go/graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules_known_fragment_names_test.go
55 lines (52 loc) · 1.31 KB
/
rules_known_fragment_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
package graphql_test
import (
"testing"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/gqlerrors"
"github.com/graphql-go/graphql/testutil"
)
func TestValidate_KnownFragmentNames_KnownFragmentNamesAreValid(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownFragmentNamesRule, `
{
human(id: 4) {
...HumanFields1
... on Human {
...HumanFields2
}
... {
name
}
}
}
fragment HumanFields1 on Human {
name
...HumanFields3
}
fragment HumanFields2 on Human {
name
}
fragment HumanFields3 on Human {
name
}
`)
}
func TestValidate_KnownFragmentNames_UnknownFragmentNamesAreInvalid(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownFragmentNamesRule, `
{
human(id: 4) {
...UnknownFragment1
... on Human {
...UnknownFragment2
}
}
}
fragment HumanFields on Human {
name
...UnknownFragment3
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Unknown fragment "UnknownFragment1".`, 4, 14),
testutil.RuleError(`Unknown fragment "UnknownFragment2".`, 6, 16),
testutil.RuleError(`Unknown fragment "UnknownFragment3".`, 12, 12),
})
}