Port 3030 hardcoded in /graphiql/bundle.js
Using browser tools you can see that /graphiql/bundle.js has port 3030 hardcoded in new u.Connection("ws://localhost:3030/graphql").
The readme doesn't specify this and it took me a while to figure out why graphiql's auto-complete wasn't working as I was using a port other than 3030 for my HTTP server.
I found that the Graphiql side had a few problems - it returns junk on larger schemas. However, if you ignore that and use an Insomnia client pointed at the standard web entry route, you get the same functionality.
I came up with a wrapper to workaround the issue:
package graphiql
import (
"bytes"
"github.com/samsarahq/thunder/graphql/graphiql"
"net/http"
"net/http/httptest"
)
func NewHandler(addr string) http.Handler {
h := http.StripPrefix("/graphiql/", graphiql.Handler())
rw := httptest.NewRecorder()
req, err := http.NewRequest(http.MethodGet, "/graphiql/bundle.js", nil)
if err != nil {
panic(err)
}
h.ServeHTTP(rw, req)
bundleJS := bytes.Replace(rw.Body.Bytes(), []byte("ws://localhost:3030/graphql"), []byte("ws://"+addr+"/graphql"), 1)
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if req.URL.Path == "/graphiql/bundle.js" {
rw.Header().Add("Content-Type", "application/javascript")
_, err = rw.Write(bundleJS)
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
}
return
}
h.ServeHTTP(rw, req)
})
}
Just hit this too, I'm guessing bundle.js is statically baked into this file?
https://github.com/samsarahq/thunder/blob/master/graphql/graphiql/statik/statik.go
using thunder in gin:
router := group.Group("")
{
router.GET("/graphql", gin.WrapH(graphql.Handler(graphqlSchema)))
urlPattern := path.Join("/graphiql", "/*filepath")
group.GET(urlPattern, gin.WrapH(
graph.NewHandler("192.168.30.30:3030"),
))
group.HEAD(urlPattern, gin.WrapH(
graph.NewHandler("192.168.30.30:3030"),
))
}