playlyfe / go-graphql

A powerful GraphQL server implementation for Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The right way to handle the "/graphql" endpoint

unreadable opened this issue · comments

I'm wondering if this library has a custom handler to set the endpoint. So far I've been using something like this
`http.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) {
result, err := executor.Execute(context, r.URL.Query()["query"][0], variables, "")

	if err != nil {
		panic(err)
	}
	json.NewEncoder(w).Encode(result)
})`

,but I don't know how good will fit in production. If there's any handler that you're using guys would be nice add it to the library, ty :)

We're also using custom handlers ourselves. What reservations do you have about your solution not working in production?

There is one minor bug, but stills work. Just wanted to know if there's a handler/method that goes better with the endpoint.

For other users interested in this, I've made a handler that supports http.Handle(), you can find it here https://github.com/krypton97/HandleGraphQL