Websocket upgrade issue with 3rd party tools
mikehawkes opened this issue · comments
Hi
Has something changed on the inbound interfaces for this library? If I try to run your standard examples, and then CURL or use Insomnia to try and run a query, I'm getting a web socket upgrade failure and the call fails. This breaks even your example on the title page.
This code fails:
func ServerGraph() {
server := &server{
...
}
schema := server.schema()
introspection.AddIntrospectionToSchema(schema)
http.Handle("/gql", graphql.Handler(schema))
err := http.ListenAndServe(":3030", nil)
if err != nil {
log.Error(err)
}
}
Dumping a websocket upgrade error when attempting to open the URL via CURL or tools such as Postman or Insomnia.
If, however, I wrap the call with a Gin handler - it works as normal:
package main
import (
"github.com/gin-gonic/gin"
"github.com/samsarahq/thunder/graphql/introspection"
"github.com/samsarahq/thunder/graphql/schemabuilder"
"github.com/samsarahq/thunder/graphql"
)
type GTest struct {
Name string
}
func main() {
d := >est{
Name: "Mike",
}
s := d.schema()
introspection.AddIntrospectionToSchema(s)
a := gin.Default()
a.POST("/gql", gin.WrapH(graphql.HTTPHandler(s)))
a.Run(":3030")
}
func (s *GTest) schema() *graphql.Schema {
b := schemabuilder.NewSchema()
s.registerQuery(b)
return b.MustBuild()
}
func (s *GTest) registerQuery(schema *schemabuilder.Schema) {
obj := schema.Query()
obj.FieldFunc("name", func() (*GTest, error) {
return >est{Name:"Mike"}, nil
})
}
Sorry - missed the HTTPHandler in place of just Handler. Works correctly now ...