Skip to content

Commit 3b13576

Browse files
committed
subscription_test: test for panic inside subscribe is recovered
1 parent b63505c commit 3b13576

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

subscription_test.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestSchemaSubscribe(t *testing.T) {
3434
},
3535
}),
3636
Query: `
37-
subscription onHelloSaid {
37+
subscription {
3838
sub_without_resolver
3939
}
4040
`,
@@ -59,7 +59,7 @@ func TestSchemaSubscribe(t *testing.T) {
5959
},
6060
}),
6161
Query: `
62-
subscription onHelloSaid {
62+
subscription {
6363
sub_with_resolver
6464
}
6565
`,
@@ -81,7 +81,7 @@ func TestSchemaSubscribe(t *testing.T) {
8181
},
8282
}),
8383
Query: `
84-
subscription onHelloSaid {
84+
subscription {
8585
sub_without_resolver
8686
xxx
8787
}
@@ -90,6 +90,28 @@ func TestSchemaSubscribe(t *testing.T) {
9090
{Errors: []string{"Cannot query field \"xxx\" on type \"Subscription\"."}},
9191
},
9292
},
93+
{
94+
Name: "panic inside subscribe is recovered",
95+
Schema: makeSubscriptionSchema(t, graphql.ObjectConfig{
96+
Name: "Subscription",
97+
Fields: graphql.Fields{
98+
"should_error": &graphql.Field{
99+
Type: graphql.String,
100+
Subscribe: func(p graphql.ResolveParams) (interface{}, error) {
101+
panic(errors.New("got a panic error"))
102+
},
103+
},
104+
},
105+
}),
106+
Query: `
107+
subscription {
108+
should_error
109+
}
110+
`,
111+
ExpectedResults: []testutil.TestResponse{
112+
{Errors: []string{"got a panic error"}},
113+
},
114+
},
93115
{
94116
Name: "subscribe with resolver changes output",
95117
Schema: makeSubscriptionSchema(t, graphql.ObjectConfig{
@@ -105,7 +127,7 @@ func TestSchemaSubscribe(t *testing.T) {
105127
},
106128
}),
107129
Query: `
108-
subscription onHelloSaid {
130+
subscription {
109131
sub_with_resolver
110132
}
111133
`,
@@ -148,7 +170,7 @@ func TestSchemaSubscribe(t *testing.T) {
148170
},
149171
}),
150172
Query: `
151-
subscription onHelloSaid {
173+
subscription {
152174
sub_with_object {
153175
field
154176
}

0 commit comments

Comments
 (0)