How do I do GraphQL in echo? I want to use this handler type (graphql-go/handler)
h := handler.New(&handler.Config{
Schema: schema,
Pretty: true,
})
in here
e.GET("/", ? )
Is there a way I could convert the above graphql handler function type to handlerFunc type expected by echo?
If h satisfies http.Handler, looks like you could just use echo.WrapHandler(h) – it's a constructor of echo.HandlerFunc which takes in an http.Handler.
https://godoc.org/github.com/labstack/echo#WrapHandler
So, you probably want
e.GET("/", echo.WrapHandler(h))
@tedkornish That worked like a charm! One more thing: How would I do a POST request to GraphQL handler using echo.POST?
If by "do" you mean "handle an HTTP request", then it would be similar:
e.POST("/", echo.WrapHandler(h))
If by "do" you mean "perform an HTTP request", then you'd want to use some sort of function like http.Post – https://golang.org/pkg/net/http/#Post.
Worked like a charm. Thank you :)
Most helpful comment
If by "do" you mean "handle an HTTP request", then it would be similar:
If by "do" you mean "perform an HTTP request", then you'd want to use some sort of function like
http.Post– https://golang.org/pkg/net/http/#Post.