Skip to content

Commit 83ba819

Browse files
authored
Merge pull request graph-gophers#398 from nmaquet/master
Fix SIGSEGV when client subs to multiple fields
2 parents dae41bd + c80e625 commit 83ba819

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

internal/exec/subscribe.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func (r *Request) Subscribe(ctx context.Context, s *resolvable.Schema, op *query
5555
}
5656
}()
5757

58+
if f == nil {
59+
return sendAndReturnClosed(&Response{Errors: []*errors.QueryError{err}})
60+
}
61+
5862
if err != nil {
5963
if _, nonNullChild := f.field.Type.(*common.NonNull); nonNullChild {
6064
return sendAndReturnClosed(&Response{Errors: []*errors.QueryError{err}})

subscription_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func (r *helloSaidResolver) HelloSaid(ctx context.Context) (chan *helloSaidEvent
5656
return c, nil
5757
}
5858

59+
func (r *rootResolver) OtherField(ctx context.Context) <-chan int32 {
60+
return make(chan int32)
61+
}
62+
5963
func (r *helloSaidEventResolver) Msg() (string, error) {
6064
return r.msg, r.err
6165
}
@@ -416,6 +420,36 @@ func TestRootOperations_validSubscriptionSchema(t *testing.T) {
416420
})
417421
}
418422

423+
func TestError_multiple_subscription_fields(t *testing.T) {
424+
gqltesting.RunSubscribes(t, []*gqltesting.TestSubscription{
425+
{
426+
Name: "Explicit schema without subscription field",
427+
Schema: graphql.MustParseSchema(`
428+
schema {
429+
query: Query
430+
subscription: Subscription
431+
}
432+
type Query {
433+
hello: String!
434+
}
435+
type Subscription {
436+
helloSaid: HelloSaidEvent!
437+
otherField: Int!
438+
}
439+
type HelloSaidEvent {
440+
msg: String!
441+
}
442+
`, &rootResolver{helloSaidResolver: &helloSaidResolver{upstream: closedUpstream(&helloSaidEventResolver{msg: "Hello world!"})}}),
443+
Query: `subscription { helloSaid { msg } otherField }`,
444+
ExpectedResults: []gqltesting.TestResponse{
445+
{
446+
Errors: []*qerrors.QueryError{qerrors.Errorf("can subscribe to at most one subscription at a time")},
447+
},
448+
},
449+
},
450+
})
451+
}
452+
419453
const schema = `
420454
schema {
421455
subscription: Subscription,

0 commit comments

Comments
 (0)