-
Notifications
You must be signed in to change notification settings - Fork 0
/
collector_test.go
104 lines (88 loc) · 2.03 KB
/
collector_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 grapher
import (
"github.com/graphql-go/graphql"
"github.com/stretchr/testify/assert"
"testing"
)
var testMutationCollection1 = graphql.Fields{
"mutation1": {
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return "mutation1", nil
},
},
}
var testMutationCollection2 = graphql.Fields{
"mutation2": {
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return "mutation2", nil
},
},
}
var testQueryCollection1 = graphql.Fields{
"query1": {
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return "query1", nil
},
},
}
var testQueryCollection2 = graphql.Fields{
"query2": {
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return "query2", nil
},
},
}
func TestMutationQueryCollector_ProperlyInitialized(t *testing.T) {
mqc := NewMutationQueryCollector()
assert.NotNil(t, mqc.Queries())
assert.NotNil(t, mqc.Mutations())
}
func TestMutationQueryCollector_QueryOnly(t *testing.T) {
mqc := NewMutationQueryCollector()
mqc.PushQueries(testQueryCollection1)
mqc.PushQueries(testQueryCollection2)
schema, err := mqc.BuildRootSchema()
assert.NoError(t, err)
assert.NotNil(t, schema)
assertSchema(t, schema, `
query {
query1
query2
}
`, map[string]interface{}{
"query1": "query1",
"query2": "query2",
})
}
func TestMutationQueryCollector_WithMutation(t *testing.T) {
mqc := NewMutationQueryCollector()
mqc.PushMutations(testMutationCollection1)
mqc.PushMutations(testMutationCollection2)
mqc.PushQueries(testQueryCollection1)
mqc.PushQueries(testQueryCollection2)
schema, err := mqc.BuildRootSchema()
assert.NoError(t, err)
assert.NotNil(t, schema)
assertSchema(t, schema, `
mutation {
mutation1
mutation2
}
`, map[string]interface{}{
"mutation1": "mutation1",
"mutation2": "mutation2",
})
assertSchema(t, schema, `
query {
query1
query2
}
`, map[string]interface{}{
"query1": "query1",
"query2": "query2",
})
}