github.com/maeglindeveloper/gqlgen@v0.13.1-0.20210413081235-57808b12a0a0/example/type-system-extension/server/server.go (about) 1 package main 2 3 import ( 4 "log" 5 "net/http" 6 "os" 7 8 "github.com/99designs/gqlgen/graphql/playground" 9 10 extension "github.com/99designs/gqlgen/example/type-system-extension" 11 "github.com/99designs/gqlgen/graphql/handler" 12 ) 13 14 const defaultPort = "8080" 15 16 func main() { 17 port := os.Getenv("PORT") 18 if port == "" { 19 port = defaultPort 20 } 21 22 http.Handle("/", playground.Handler("GraphQL playground", "/query")) 23 http.Handle("/query", handler.NewDefaultServer( 24 extension.NewExecutableSchema( 25 extension.Config{ 26 Resolvers: extension.NewRootResolver(), 27 Directives: extension.DirectiveRoot{ 28 EnumLogging: extension.EnumLogging, 29 FieldLogging: extension.FieldLogging, 30 InputLogging: extension.InputLogging, 31 ObjectLogging: extension.ObjectLogging, 32 ScalarLogging: extension.ScalarLogging, 33 UnionLogging: extension.UnionLogging, 34 }, 35 }, 36 ), 37 )) 38 39 log.Printf("connect to http://localhost:%s/ for GraphQL playground", port) 40 log.Fatal(http.ListenAndServe(":"+port, nil)) 41 }