Echo: GraphQL in Echo

Created on 31 Dec 2016  Â·  4Comments  Â·  Source: labstack/echo

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?

question

Most helpful comment

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.

All 4 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dre1080 picture dre1080  Â·  4Comments

linux-support picture linux-support  Â·  3Comments

ellisonleao picture ellisonleao  Â·  3Comments

jeyldii picture jeyldii  Â·  4Comments

arun0009 picture arun0009  Â·  3Comments