Skip to content

Commit

Permalink
remove call to deprecated function
Browse files Browse the repository at this point in the history
NewDefaultServer was marked deprecated as its intended use was only for testing.
This replaces calls to that function with the same calls.

Signed-off-by: Mike Mason <[email protected]>
  • Loading branch information
mikemrm committed Jan 10, 2025
1 parent b514140 commit 4812bc2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
22 changes: 21 additions & 1 deletion internal/graphapi/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ package graphapi
import (
"fmt"
"net/http"
"time"

"github.com/99designs/gqlgen-contrib/prometheus"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/handler/lru"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/labstack/echo/v4"
"github.com/vektah/gqlparser/v2/ast"
"github.com/wundergraph/graphql-go-tools/pkg/playground"
"go.infratographer.com/x/gqlgenx/oteltracing"
"go.uber.org/zap"
Expand Down Expand Up @@ -49,14 +54,29 @@ type Handler struct {

// Handler returns an http handler for a graph resolver
func (r *Resolver) Handler(withPlayground bool, middleware []echo.MiddlewareFunc) *Handler {
srv := handler.NewDefaultServer(
srv := handler.New(
NewExecutableSchema(
Config{
Resolvers: r,
},
),
)

srv.AddTransport(transport.Websocket{
KeepAlivePingInterval: 10 * time.Second, //nolint:mnd
})
srv.AddTransport(transport.Options{})
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})
srv.AddTransport(transport.MultipartForm{})

srv.SetQueryCache(lru.New[*ast.QueryDocument](1000)) //nolint:mnd

srv.Use(extension.Introspection{})
srv.Use(extension.AutomaticPersistedQuery{
Cache: lru.New[string](100), //nolint:mnd
})

srv.Use(oteltracing.Tracer{})

prometheus.Register()
Expand Down
29 changes: 28 additions & 1 deletion internal/graphapi/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ import (
"os"
"strings"
"testing"
"time"

"entgo.io/ent/dialect"
"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/handler/lru"
"github.com/99designs/gqlgen/graphql/handler/transport"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
"github.com/vektah/gqlparser/v2/ast"
"go.infratographer.com/x/echojwtx"
"go.infratographer.com/x/events"
"go.infratographer.com/x/goosex"
Expand Down Expand Up @@ -150,7 +156,7 @@ func teardownDB() {
}

func graphTestClient(entClient *ent.Client) testclient.TestClient {
return testclient.NewClient(&http.Client{Transport: localRoundTripper{handler: handler.NewDefaultServer(
return testclient.NewClient(&http.Client{Transport: localRoundTripper{handler: newDefaultServer(
graphapi.NewExecutableSchema(
graphapi.Config{Resolvers: graphapi.NewResolver(entClient, zap.NewNop().Sugar())},
))}}, "graph")
Expand All @@ -170,3 +176,24 @@ func (l localRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {

return w.Result(), nil
}

func newDefaultServer(es graphql.ExecutableSchema) *handler.Server {
srv := handler.New(es)

srv.AddTransport(transport.Websocket{
KeepAlivePingInterval: 10 * time.Second,
})
srv.AddTransport(transport.Options{})
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})
srv.AddTransport(transport.MultipartForm{})

srv.SetQueryCache(lru.New[*ast.QueryDocument](1000))

srv.Use(extension.Introspection{})
srv.Use(extension.AutomaticPersistedQuery{
Cache: lru.New[string](100),
})

return srv
}

0 comments on commit 4812bc2

Please sign in to comment.