thunder icon indicating copy to clipboard operation
thunder copied to clipboard

Port 3030 hardcoded in /graphiql/bundle.js

Open lmuench opened this issue 7 years ago • 4 comments

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.

lmuench avatar Feb 27 '19 11:02 lmuench

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.

mikehawkes avatar Mar 02 '19 10:03 mikehawkes

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)
	})
}

vearutop avatar Jun 18 '19 16:06 vearutop

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

carwyn avatar Mar 03 '21 10:03 carwyn

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"),
    ))
}

yangDL avatar Apr 19 '21 03:04 yangDL