Skip to content

Commit b63505c

Browse files
committed
subscription_test: added more tests for resolver behaviour
1 parent ab87417 commit b63505c

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

subscription_test.go

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ func TestSchemaSubscribe(t *testing.T) {
1818
Name: "Subscription",
1919
Fields: graphql.Fields{
2020
"sub_without_resolver": &graphql.Field{
21-
Type: graphql.String,
22-
Subscribe: makeSubscribeToStringFunction([]string{"a", "b", "c"}),
23-
Resolve: func(p graphql.ResolveParams) (interface{}, error) { // TODO remove dummy resolver
24-
return p.Source, nil
25-
},
21+
Type: graphql.String,
22+
Subscribe: makeSubscribeToMapFunction([]map[string]interface{}{
23+
{
24+
"sub_without_resolver": "a",
25+
},
26+
{
27+
"sub_without_resolver": "b",
28+
},
29+
{
30+
"sub_without_resolver": "c",
31+
},
32+
}),
2633
},
2734
},
2835
}),
@@ -37,6 +44,31 @@ func TestSchemaSubscribe(t *testing.T) {
3744
{Data: `{ "sub_without_resolver": "c" }`},
3845
},
3946
},
47+
{
48+
Name: "subscribe with resolver",
49+
Schema: makeSubscriptionSchema(t, graphql.ObjectConfig{
50+
Name: "Subscription",
51+
Fields: graphql.Fields{
52+
"sub_with_resolver": &graphql.Field{
53+
Type: graphql.String,
54+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
55+
return p.Source, nil
56+
},
57+
Subscribe: makeSubscribeToStringFunction([]string{"a", "b", "c"}),
58+
},
59+
},
60+
}),
61+
Query: `
62+
subscription onHelloSaid {
63+
sub_with_resolver
64+
}
65+
`,
66+
ExpectedResults: []testutil.TestResponse{
67+
{Data: `{ "sub_with_resolver": "a" }`},
68+
{Data: `{ "sub_with_resolver": "b" }`},
69+
{Data: `{ "sub_with_resolver": "c" }`},
70+
},
71+
},
4072
{
4173
Name: "receive query validation error",
4274
Schema: makeSubscriptionSchema(t, graphql.ObjectConfig{
@@ -98,7 +130,7 @@ func TestSchemaSubscribe(t *testing.T) {
98130
},
99131
},
100132
}),
101-
Resolve: func(p graphql.ResolveParams) (interface{}, error) { // TODO remove dummy resolver
133+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
102134
return p.Source, nil
103135
},
104136
Subscribe: makeSubscribeToMapFunction([]map[string]interface{}{

0 commit comments

Comments
 (0)