Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription error: Error: Socket closed with event 1002 RSV1 set, bad opcode 7, bad MASK at Object.error #3007

Open
asdutoit opened this issue Apr 15, 2024 · 0 comments

Comments

@asdutoit
Copy link

I followed the gqlgen guide on setting up graphql in a Gin project and then tried to also add support for subscriptions.
Everything works flawlessly except for subscriptions.
When testing it out in the playground, I get the following error:

Error: Socket closed with event 1002 RSV1 set, bad opcode 7, bad MASK at Object.error

Screenshot 2024-04-15 at 06 44 29

I am sure I am just missing something or made a mistake in my configuration, but for the life of me, cannot see where.

I created the following graphql handler which includes the AddTransport method for subscriptions:

// graphql.go

func GraphqlHandler() gin.HandlerFunc {
	// NewExecutableSchema and Config are in the generated.go file
	// Resolver is in the resolver.go file
	h := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))

	h.AddTransport(&transport.Websocket{}) // <== Added Subscription support

	return func(c *gin.Context) {
		h.ServeHTTP(c.Writer, c.Request)
	}
}

// Defining the Playground handler
func PlaygroundHandler() gin.HandlerFunc {
	h := playground.Handler("GraphQL", "/query")

	return func(c *gin.Context) {
		h.ServeHTTP(c.Writer, c.Request)
	}
}

My routes file:

// routes.go
func SetupRouter() *gin.Engine {
	r := gin.Default()
        
        // ... removed for brevity
	
	r.Any("/query", graphql.GraphqlHandler())
	r.GET("/", graphql.PlaygroundHandler())

        // ... removed for brevity

	return r
}

I would appreciate any assistance.
Many thanks!

versions

  • gqlgen version: v0.17.45
  • go version: go1.21.5 darwin/arm64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant