github.com/maeglindeveloper/gqlgen@v0.13.1-0.20210413081235-57808b12a0a0/example/federation/products/server.go (about) 1 //go:generate go run ../../../testdata/gqlgen.go 2 package main 3 4 import ( 5 "log" 6 "net/http" 7 "os" 8 9 "github.com/99designs/gqlgen/example/federation/products/graph" 10 "github.com/99designs/gqlgen/example/federation/products/graph/generated" 11 "github.com/99designs/gqlgen/graphql/handler" 12 "github.com/99designs/gqlgen/graphql/handler/debug" 13 "github.com/99designs/gqlgen/graphql/playground" 14 ) 15 16 const defaultPort = "4002" 17 18 func main() { 19 port := os.Getenv("PORT") 20 if port == "" { 21 port = defaultPort 22 } 23 24 srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}})) 25 srv.Use(&debug.Tracer{}) 26 27 http.Handle("/", playground.Handler("GraphQL playground", "/query")) 28 http.Handle("/query", srv) 29 30 log.Printf("connect to http://localhost:%s/ for GraphQL playground", port) 31 log.Fatal(http.ListenAndServe(":"+port, nil)) 32 }