Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate NewDefaultServer #3404

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion _examples/chat/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"runtime"
"sync"
"testing"
"time"

"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -14,7 +16,12 @@ import (
)

func TestChatSubscriptions(t *testing.T) {
c := client.New(handler.NewDefaultServer(NewExecutableSchema(New())))
srv := handler.New(NewExecutableSchema(New()))
srv.AddTransport(transport.Websocket{
KeepAlivePingInterval: time.Second,
})
srv.AddTransport(transport.POST{})
c := client.New(srv)

const batchSize = 128
var wg sync.WaitGroup
Expand Down
11 changes: 8 additions & 3 deletions _examples/config/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ import (

todo "github.com/99designs/gqlgen/_examples/config"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
)

func main() {
http.Handle("/", playground.Handler("Todo", "/query"))
http.Handle("/query", handler.NewDefaultServer(
srv := handler.New(
todo.NewExecutableSchema(todo.New()),
))
)
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})

http.Handle("/", playground.Handler("Todo", "/query"))
http.Handle("/query", srv)
log.Fatal(http.ListenAndServe(":8081", nil))
}
7 changes: 6 additions & 1 deletion _examples/dataloader/dataloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package dataloader
import (
"testing"

"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/stretchr/testify/require"

"github.com/99designs/gqlgen/client"
Expand All @@ -11,7 +13,10 @@ import (
)

func TestTodo(t *testing.T) {
c := client.New(LoaderMiddleware(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: &Resolver{}}))))
srv := handler.New(NewExecutableSchema(Config{Resolvers: &Resolver{}}))
srv.AddTransport(transport.POST{})
srv.Use(extension.Introspection{})
c := client.New(LoaderMiddleware(srv))

t.Run("create a new todo", func(t *testing.T) {
var resp any
Expand Down
11 changes: 8 additions & 3 deletions _examples/dataloader/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import (

"github.com/99designs/gqlgen/_examples/dataloader"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
)

func main() {
router := http.NewServeMux()

router.Handle("/", playground.Handler("Dataloader", "/query"))
router.Handle("/query", handler.NewDefaultServer(
srv := handler.New(
dataloader.NewExecutableSchema(dataloader.Config{Resolvers: &dataloader.Resolver{}}),
))
)
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})

router.Handle("/", playground.Handler("Dataloader", "/query"))
router.Handle("/query", srv)

log.Println("connect to http://localhost:8082/ for graphql playground")
log.Fatal(http.ListenAndServe(":8082", dataloader.LoaderMiddleware(router)))
Expand Down
9 changes: 7 additions & 2 deletions _examples/embedding/subdir/embedding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package subdir
import (
"testing"

"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/stretchr/testify/require"

"github.com/99designs/gqlgen/_examples/embedding/subdir/gendir"
Expand All @@ -11,7 +12,9 @@ import (
)

func TestEmbeddingWorks(t *testing.T) {
c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: &Resolver{}})))
srv := handler.New(NewExecutableSchema(Config{Resolvers: &Resolver{}}))
srv.AddTransport(transport.POST{})
c := client.New(srv)
var resp struct {
InSchemadir string
Parentdir string
Expand All @@ -30,7 +33,9 @@ func TestEmbeddingWorks(t *testing.T) {
}

func TestEmbeddingWorksInGendir(t *testing.T) {
c := client.New(handler.NewDefaultServer(gendir.NewExecutableSchema(gendir.Config{Resolvers: &GendirResolver{}})))
srv := handler.New(gendir.NewExecutableSchema(gendir.Config{Resolvers: &GendirResolver{}}))
srv.AddTransport(transport.POST{})
c := client.New(srv)
var resp struct {
InSchemadir string
Parentdir string
Expand Down
11 changes: 10 additions & 1 deletion _examples/enum/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ import (

"github.com/99designs/gqlgen/_examples/enum/api"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
)

func main() {
srv := handler.New(
api.NewExecutableSchema(api.Config{Resolvers: &api.Resolver{}}),
)

srv.AddTransport(transport.Options{})
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})

http.Handle("/", playground.Handler("Enum", "/query"))
http.Handle("/query", handler.NewDefaultServer(api.NewExecutableSchema(api.Config{Resolvers: &api.Resolver{}})))
http.Handle("/query", srv)
log.Fatal(http.ListenAndServe(":8081", nil))
}
9 changes: 8 additions & 1 deletion _examples/federation/accounts/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/99designs/gqlgen/_examples/federation/accounts/graph"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/debug"
"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
)

Expand All @@ -20,7 +22,12 @@ func main() {
port = defaultPort
}

srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))
srv := handler.New(
graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}),
)
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})
srv.Use(extension.Introspection{})
srv.Use(&debug.Tracer{})

http.Handle("/", playground.Handler("GraphQL playground", "/query"))
Expand Down
9 changes: 8 additions & 1 deletion _examples/federation/products/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/99designs/gqlgen/_examples/federation/products/graph"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/debug"
"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
)

Expand All @@ -20,7 +22,12 @@ func main() {
port = defaultPort
}

srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))
srv := handler.New(
graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}),
)
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})
srv.Use(extension.Introspection{})
srv.Use(&debug.Tracer{})

http.Handle("/", playground.Handler("GraphQL playground", "/query"))
Expand Down
9 changes: 8 additions & 1 deletion _examples/federation/reviews/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/99designs/gqlgen/_examples/federation/reviews/graph"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/debug"
"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
)

Expand All @@ -20,7 +22,12 @@ func main() {
port = defaultPort
}

srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))
srv := handler.New(
graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}),
)
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})
srv.Use(extension.Introspection{})
srv.Use(&debug.Tracer{})

http.Handle("/", playground.Handler("GraphQL playground", "/query"))
Expand Down
7 changes: 6 additions & 1 deletion _examples/federation/subgraphs/subgraphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/debug"
"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
)

Expand Down Expand Up @@ -57,7 +59,10 @@ func newServer(name, port string, schema graphql.ExecutableSchema) *http.Server
if port == "" {
panic(fmt.Errorf("port for %s is empty", name))
}
srv := handler.NewDefaultServer(schema)
srv := handler.New(schema)
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})
srv.Use(extension.Introspection{})
srv.Use(&debug.Tracer{})
mux := http.NewServeMux()
mux.Handle("/", playground.Handler("GraphQL playground", "/query"))
Expand Down
4 changes: 3 additions & 1 deletion _examples/fileupload/fileupload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (

func TestFileUpload(t *testing.T) {
resolver := &Stub{}
srv := httptest.NewServer(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolver})))
h := handler.New(NewExecutableSchema(Config{Resolvers: resolver}))
h.AddTransport(transport.MultipartForm{})
srv := httptest.NewServer(h)
defer srv.Close()
gql := gqlclient.New(srv.Config.Handler, gqlclient.Path("/graphql"))

Expand Down
2 changes: 1 addition & 1 deletion _examples/fileupload/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {

var mb int64 = 1 << 20

srv := handler.NewDefaultServer(fileupload.NewExecutableSchema(fileupload.Config{Resolvers: resolver}))
srv := handler.New(fileupload.NewExecutableSchema(fileupload.Config{Resolvers: resolver}))
srv.AddTransport(transport.POST{})
srv.AddTransport(transport.MultipartForm{
MaxMemory: 32 * mb,
Expand Down
7 changes: 6 additions & 1 deletion _examples/scalars/scalar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"testing"
"time"

"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/stretchr/testify/require"

"github.com/99designs/gqlgen/client"
Expand All @@ -22,7 +24,10 @@ type RawUser struct {
}

func TestScalars(t *testing.T) {
c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: &Resolver{}})))
srv := handler.New(NewExecutableSchema(Config{Resolvers: &Resolver{}}))
srv.AddTransport(transport.POST{})
srv.Use(extension.Introspection{})
c := client.New(srv)

t.Run("marshaling", func(t *testing.T) {
var resp struct {
Expand Down
9 changes: 8 additions & 1 deletion _examples/scalars/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ import (

"github.com/99designs/gqlgen/_examples/scalars"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
)

func main() {
srv := handler.New(
scalars.NewExecutableSchema(scalars.Config{Resolvers: &scalars.Resolver{}}),
)
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})

http.Handle("/", playground.Handler("Starwars", "/query"))
http.Handle("/query", handler.NewDefaultServer(scalars.NewExecutableSchema(scalars.Config{Resolvers: &scalars.Resolver{}})))
http.Handle("/query", srv)

log.Fatal(http.ListenAndServe(":8084", nil))
}
5 changes: 4 additions & 1 deletion _examples/selection/selection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package selection
import (
"testing"

"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/stretchr/testify/require"

"github.com/99designs/gqlgen/client"
"github.com/99designs/gqlgen/graphql/handler"
)

func TestSelection(t *testing.T) {
c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: &Resolver{}})))
srv := handler.New(NewExecutableSchema(Config{Resolvers: &Resolver{}}))
srv.AddTransport(transport.POST{})
c := client.New(srv)

query := `{
events {
Expand Down
9 changes: 8 additions & 1 deletion _examples/selection/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ import (

"github.com/99designs/gqlgen/_examples/selection"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
)

func main() {
srv := handler.New(
selection.NewExecutableSchema(selection.Config{Resolvers: &selection.Resolver{}}),
)
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})

http.Handle("/", playground.Handler("Selection Demo", "/query"))
http.Handle("/query", handler.NewDefaultServer(selection.NewExecutableSchema(selection.Config{Resolvers: &selection.Resolver{}})))
http.Handle("/query", srv)
log.Fatal(http.ListenAndServe(":8086", nil))
}
4 changes: 3 additions & 1 deletion _examples/starwars/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (

"github.com/99designs/gqlgen/_examples/starwars/generated"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/transport"
)

func BenchmarkSimpleQueryNoArgs(b *testing.B) {
server := handler.NewDefaultServer(generated.NewExecutableSchema(NewResolver()))
server := handler.New(generated.NewExecutableSchema(NewResolver()))
server.AddTransport(transport.POST{})

q := `{"query":"{ search(text:\"Luke\") { ... on Human { starships { name } } } }"}`

Expand Down
6 changes: 5 additions & 1 deletion _examples/starwars/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import (
"github.com/99designs/gqlgen/_examples/starwars/generated"
"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
)

func main() {
srv := handler.NewDefaultServer(generated.NewExecutableSchema(starwars.NewResolver()))
srv := handler.New(generated.NewExecutableSchema(starwars.NewResolver()))
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})

srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (res any, err error) {
rc := graphql.GetFieldContext(ctx)
fmt.Println("Entered", rc.Object, rc.Field.Name)
Expand Down
7 changes: 6 additions & 1 deletion _examples/starwars/starwars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package starwars
import (
"testing"

"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/stretchr/testify/require"

"github.com/99designs/gqlgen/_examples/starwars/generated"
Expand All @@ -12,7 +14,10 @@ import (
)

func TestStarwars(t *testing.T) {
c := client.New(handler.NewDefaultServer(generated.NewExecutableSchema(NewResolver())))
srv := handler.New(generated.NewExecutableSchema(NewResolver()))
srv.AddTransport(transport.POST{})
srv.Use(extension.Introspection{})
c := client.New(srv)

t.Run("Lukes starships", func(t *testing.T) {
var resp struct {
Expand Down
Loading
Loading