GraphQL
When using github.com/99designs/gqlgen
import (
"github.com/sitebatch/waffle-go/contrib/99designs/gqlgen"
"github.com/sitebatch/waffle-go"
waffleHttp "github.com/sitebatch/waffle-go/contrib/net/http"
)
mux := http.NewServeMux()
gqlHandler := func() http.HandlerFunc {
srv := handler.New(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))
srv.AddTransport(transport.Options{})
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})
srv.SetQueryCache(lru.New[*ast.QueryDocument](1000))
// Apply WAF middleware for gqlgen
srv.Use(gqlgen.WafMiddleware{})
srv.Use(extension.Introspection{})
srv.Use(extension.AutomaticPersistedQuery{
Cache: lru.New[string](100),
})
return func(w http.ResponseWriter, r *http.Request) {
srv.ServeHTTP(w, r)
}
}
mux.Handle("/query", gqlHandler())
// Apply WAF middleware for the HTTP Server
handler := waffleHttp.WafMiddleware(mux)
waffle.Start()