Separate Playground Handler from GraphQL Handler and make it configurable
pkosiec opened this issue ยท 3 comments
Hi,
Very cool project, thank you for active development! ๐
I would like to propose an improvement to Playground and GraphQL handlers:
- Modify Playground Handler to just serve the GraphQL Playground page
- Make Playground Handler configurable, to be able to point on different endpoint for GraphQL API.
For example, similarly to gqlgen, I would like to run Playground on /
(for GET
requests) and actual GraphQL handler on /graphql
(POST
requests), like this:
// github.com/gorilla/mux
r := mux.NewRouter()
// assuming that PlaygroundHandler takes two arguments: title and endpoint
r.HandleFunc("/", gw.PlaygroundHandler("Sample Playground", "/graphql")).Methods(http.MethodGet)
r.Handle("/graphql", gw.GraphQLHandler).Methods(http.MethodPost)
It would be great to have the separation of concerns - that's why I would suggest modifying the PlaygroundHandler
in the following way:
func (g *Gateway) PlaygroundHandler(w http.ResponseWriter, r *http.Request) {
// This handler would serve just the GraphQL Playground, nothing more.
// Remove the following lines:
// if r.Method == http.MethodPost {
// g.GraphQLHandler(w, r)
// return
// }
w.Write(playgroundContent)
}
However, it would be a breaking change, so that's probably something to discuss. What do you think?
If you would like to, I can prepare the PR for this change.
Cheers!
Hey @pkosiec! Thanks for being patient while I'm slow to respond.
I think it makes sense to provide a way to have these be separate endpoints. I think having one handler that provides both behaviors is also nice for people that want it. Can you think of a better name for PlaygroundHandler
for the one that does both?
Hi @AlecAivazis,
Thanks for reply. Naming things is hard ๐ I was thinking a bit and I have three ideas:
CombinedHandler
ConsolidatedHandler
UnifiedHandler
I'm not saying they're the best, but they're the only ones I could come up with. What do you think?
Thanks for opening @pkosiec! This was added in v0.2.8