Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Port 3030 hardcoded in /graphiql/bundle.js #226

Open
lmuench opened this issue Feb 27, 2019 · 4 comments
Open

Port 3030 hardcoded in /graphiql/bundle.js #226

lmuench opened this issue Feb 27, 2019 · 4 comments

Comments

@lmuench
Copy link

lmuench commented Feb 27, 2019

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.

@mikehawkes
Copy link

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.

@vearutop
Copy link

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

@carwyn
Copy link

carwyn commented Mar 3, 2021

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

@yangDL
Copy link

yangDL commented Apr 19, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants