diff --git a/subscription.go b/subscription.go index 2fa49d7..cf73de9 100644 --- a/subscription.go +++ b/subscription.go @@ -181,7 +181,10 @@ func (sc *SubscriptionContext) GetSubscription(id string) *Subscription { if sc.subscriptions == nil { return nil } - sub, _ := sc.subscriptions[id] + sub, found := sc.subscriptions[id] + if !found { + return nil + } return &sub } @@ -617,6 +620,9 @@ func (sc *SubscriptionClient) Run() error { } sub := sc.context.GetSubscription(message.ID) + if sub == nil { + sub = &Subscription{} + } go sc.protocol.OnMessage(sc.context, *sub, message) } } diff --git a/subscription_graphql_ws.go b/subscription_graphql_ws.go index 33e798f..475d9b3 100644 --- a/subscription_graphql_ws.go +++ b/subscription_graphql_ws.go @@ -110,6 +110,9 @@ func (gws *graphqlWS) OnMessage(ctx *SubscriptionContext, subscription Subscript Data *json.RawMessage Errors Errors } + if subscription.handler == nil { + return + } err := json.Unmarshal(message.Payload, &out) if err != nil { diff --git a/subscriptions_transport_ws.go b/subscriptions_transport_ws.go index d76b601..abd3303 100644 --- a/subscriptions_transport_ws.go +++ b/subscriptions_transport_ws.go @@ -138,6 +138,9 @@ func (stw *subscriptionsTransportWS) OnMessage(ctx *SubscriptionContext, subscri Data *json.RawMessage Errors Errors } + if subscription.handler == nil { + return + } err := json.Unmarshal(message.Payload, &out) if err != nil {