Closed maapteh closed 3 years ago
@maapteh thanks a lot for working on this PR 👍 –– very interesting improvement for the examples/todo
.
I think GraphQL Playground is very useful tool, but I think the examples/todo
aims to demonstrate how to use graphql-go/graphql
as a HTTP endpoint & how to integrate it with a Web App.
But I definitely understand your motivation to improve the examples/todo
to show how to use graphql-go/graphql
via HTTP POST
and integrate it with GraphQL Playground
.
For this type of use cases I would recommend to use graphql-go/handler
which handles both HTTP verbs: GET
& POST
.
Using graphql-go/handler
and the examples/todo
schema, both can be integrated to have GraphQL Playground
working, Eg:
package main
import (
"log"
"net/http"
"github.com/graphql-go/graphql/examples/todo/schema"
"github.com/graphql-go/handler"
)
func main() {
h := handler.New(&handler.Config{
Schema: &schema.TodoSchema,
Pretty: true,
GraphiQL: false,
Playground: true,
})
http.Handle("/graphql", h)
log.Println("server running on port :8080")
http.ListenAndServe(":8080", nil)
}
I went ahead and sent a PR#574 for exposing the TodoSchema
so it can be use as shown above.
Closing this one in favor of: https://github.com/graphql-go/graphql/pull/574
I decided it would be nice to have an example with POST. Since it's more common. I also updated the playground which offers more options. So:
closes #420
credits to @atombender who showed an example :)