Skip to content

Commit

Permalink
Allow adding transports before defaults (#272)
Browse files Browse the repository at this point in the history
As I mentioned in #80 (comment), one could not override default transports now.

With this small change, one could set up own transport, because first transport get's selected:
https://github.com/99designs/gqlgen/blob/fb67b709af4f0c5ba6eff8222c728b076a6eb09b/graphql/handler/server.go#L98

It will allow users, for example, to introduce batching with a bramble plugin, as I also mentioned in comment: #80 (comment).
  • Loading branch information
benzolium authored Jul 16, 2024
1 parent 2e923b1 commit f24f90e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ func (g *Gateway) UpdateSchemas(interval time.Duration) {
func (g *Gateway) Router(cfg *Config) http.Handler {
mux := http.NewServeMux()

gatewayHandler := handler.New(g.ExecutableSchema)
for _, plugin := range g.plugins {
plugin.SetupGatewayHandler(gatewayHandler)
}
// Duplicated from `handler.NewDefaultServer` minus
// the websocket transport and persisted query extension
gatewayHandler := handler.New(g.ExecutableSchema)
gatewayHandler.AddTransport(transport.Options{})
gatewayHandler.AddTransport(transport.GET{})
gatewayHandler.AddTransport(transport.POST{})
Expand All @@ -53,10 +56,6 @@ func (g *Gateway) Router(cfg *Config) http.Handler {
gatewayHandler.Use(extension.Introspection{})
}

for _, plugin := range g.plugins {
plugin.SetupGatewayHandler(gatewayHandler)
}

mux.Handle("/query", applyMiddleware(otelhttp.NewHandler(gatewayHandler, "/query"), debugMiddleware))

for _, plugin := range g.plugins {
Expand Down

0 comments on commit f24f90e

Please sign in to comment.