/
rules_fragments_on_composite_types_test.go
87 lines (84 loc) · 2.83 KB
/
rules_fragments_on_composite_types_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
package graphql_test
import (
"testing"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/gqlerrors"
"github.com/graphql-go/graphql/testutil"
)
func TestValidate_FragmentsOnCompositeTypes_ObjectIsValidFragmentType(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.FragmentsOnCompositeTypesRule, `
fragment validFragment on Dog {
barks
}
`)
}
func TestValidate_FragmentsOnCompositeTypes_InterfaceIsValidFragmentType(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.FragmentsOnCompositeTypesRule, `
fragment validFragment on Pet {
name
}
`)
}
func TestValidate_FragmentsOnCompositeTypes_ObjectIsValidInlineFragmentType(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.FragmentsOnCompositeTypesRule, `
fragment validFragment on Pet {
... on Dog {
barks
}
}
`)
}
func TestValidate_FragmentsOnCompositeTypes_InlineFragmentWithoutTypeIsValid(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.FragmentsOnCompositeTypesRule, `
fragment validFragment on Pet {
... {
name
}
}
`)
}
func TestValidate_FragmentsOnCompositeTypes_UnionIsValidFragmentType(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.FragmentsOnCompositeTypesRule, `
fragment validFragment on CatOrDog {
__typename
}
`)
}
func TestValidate_FragmentsOnCompositeTypes_ScalarIsInvalidFragmentType(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.FragmentsOnCompositeTypesRule, `
fragment scalarFragment on Boolean {
bad
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "scalarFragment" cannot condition on non composite type "Boolean".`, 2, 34),
})
}
func TestValidate_FragmentsOnCompositeTypes_EnumIsInvalidFragmentType(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.FragmentsOnCompositeTypesRule, `
fragment scalarFragment on FurColor {
bad
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "scalarFragment" cannot condition on non composite type "FurColor".`, 2, 34),
})
}
func TestValidate_FragmentsOnCompositeTypes_InputObjectIsInvalidFragmentType(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.FragmentsOnCompositeTypesRule, `
fragment inputFragment on ComplexInput {
stringField
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "inputFragment" cannot condition on non composite type "ComplexInput".`, 2, 33),
})
}
func TestValidate_FragmentsOnCompositeTypes_ScalarIsInvalidInlineFragmentType(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.FragmentsOnCompositeTypesRule, `
fragment invalidFragment on Pet {
... on String {
barks
}
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment cannot condition on non composite type "String".`, 3, 16),
})
}