@@ -192,6 +192,7 @@ import (
192192 " encoding/json"
193193 " slices"
194194 " github.com/wundergraph/cosmo/router/core"
195+ " github.com/wundergraph/cosmo/router/pkg/pubsub/datasource"
195196 " github.com/wundergraph/cosmo/router/pkg/pubsub/nats"
196197)
197198
@@ -205,7 +206,7 @@ type MyModule struct {}
205206// Implement SubscriptionOnStartHandler for authorization
206207func (m *MyModule ) SubscriptionOnStart (ctx SubscriptionOnStartHandlerContext ) error {
207208 // Check if the provider is NATS
208- if ctx.SubscriptionEventConfiguration ().ProviderType () != pubsub .ProviderTypeNats {
209+ if ctx.SubscriptionEventConfiguration ().ProviderType () != datasource .ProviderTypeNats {
209210 return nil
210211 }
211212
@@ -227,11 +228,11 @@ func (m *MyModule) SubscriptionOnStart(ctx SubscriptionOnStartHandlerContext) er
227228 // Check if the client has the required permissions
228229 clientAllowedEntitiesIds , found := ctx.Authentication ().Claims ()[" readEmployee" ]
229230 if !found {
230- return & core.HttpError {
231- Code: http. StatusForbidden ,
232- Message: " client is not allowed to read employees " ,
233- CloseSubscription: true ,
234- }
231+ return core.NewHttpGraphqlError (
232+ " client is not allowed to read employees " ,
233+ http. StatusText (http. StatusForbidden ) ,
234+ http. StatusForbidden
235+ )
235236 }
236237
237238 return nil
@@ -240,7 +241,7 @@ func (m *MyModule) SubscriptionOnStart(ctx SubscriptionOnStartHandlerContext) er
240241// Implement StreamReceiveEventHandler for event filtering and transformation
241242func (m *MyModule ) OnReceiveEvents (ctx StreamReceiveEventHandlerContext , events []core .StreamEvent ) ([]core .StreamEvent , error ) {
242243 // Check if the provider is NATS
243- if ctx.SubscriptionEventConfiguration ().ProviderType () != pubsub .ProviderTypeNats {
244+ if ctx.SubscriptionEventConfiguration ().ProviderType () != datasource .ProviderTypeNats {
244245 return events, nil
245246 }
246247
@@ -339,7 +340,7 @@ Here's an example of how to transform events before publishing:
339340// Implement StreamPublishEventHandler for event transformation
340341func (m *MyModule ) OnPublishEvents (ctx StreamPublishEventHandlerContext , events []StreamEvent ) ([]StreamEvent , error ) {
341342 // Check if the provider is NATS
342- if ctx.PublishEventConfiguration ().ProviderType () != pubsub .ProviderTypeNats {
343+ if ctx.PublishEventConfiguration ().ProviderType () != datasource .ProviderTypeNats {
343344 return events, nil
344345 }
345346
0 commit comments