Open frederikhors opened 3 years ago
I think gqlgen should support fasthttp as offically.
I originally requested the support and if gofiber gets the official from gqlgen then it will just make gofiber more powerful.
I'm not a fan of fasthttp/gofiber - any application using a datastore for a backend will not see the performance gains over the stdlib this project claims.
However, I note there's a forked version of gqlgen with support at https://github.com/arsmn/fastgql.
And if someone wanted to implement, gqlgen's plugin system should make this possible.
However, I note there's a forked version of gqlgen with support at https://github.com/arsmn/fastgql.
Is old, doesn't work and there is no docs.
And not to confuse with the other fastgql, whose filtering, pagination, sorting and aggregation model is fine.
And not to confuse with the other fastgql, whose filtering, pagination, sorting and aggregation model is fine.
I think this is still not fully "supported". The only hope is to have something official, perhaps among the plugins officially supported by gqlgen.
It seems adding partial fasthttp support is really hard if we dont think fork. Code has too many hardcoded net/http connections.
This is a final missing piece of fiber x gqlgen.
It will be very nice to have official support of Fiber/fasthttp.
Any news on this?
@gaby It worked for me using the following code. This boilerplate code was written by ChatGPT (while i slightly edited the code to include the wrapHandler func to make the bridge b/w the graphql handler and fiber with fasthttpadaptor).
This works for me, at least I didn't run into any complications so far. You can try and let me know. Also, I didn't test this with subscriptions.
package main
import (
"your-module/graph" // Import the generated code from gqlgen
"net/http"
"github.com/gofiber/fiber/v2"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/valyala/fasthttp/fasthttpadaptor"
)
func wrapHandler(f func(http.ResponseWriter, *http.Request)) func(ctx *fiber.Ctx) {
return func(ctx *fiber.Ctx) {
fasthttpadaptor.NewFastHTTPHandler(http.HandlerFunc(f))(ctx.Context())
}
}
func main() {
app := fiber.New()
// Create a gqlgen handler
h := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))
// Serve GraphQL API
app.Post("/graphql", func(c *fiber.Ctx) error {
wrapHandler(h.ServeHTTP)(c)
return nil
})
// Serve GraphQL Playground
app.Get("/playground", func(c *fiber.Ctx) error {
wrapHandler(playground.Handler("GraphQL", "/graphql"))(c)
return nil
})
// Start the server
app.Listen(":3000")
}
@shyaaam when using the adapter, does it mean the speed decreases from gofiber to net/http?
I think we should add support for framework like GoFiber.
Someone has already tried: https://github.com/Just4Ease/fiber-gqlgen/blob/master/handler.go.
Here a discussion on gofiber: https://github.com/gofiber/fiber/issues/403.