forked from benawad/node-graphql-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
29 lines (22 loc) · 711 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main
import (
"log"
"net/http"
"os"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/fibs7000/go-graphql-benchmark/graph"
"github.com/fibs7000/go-graphql-benchmark/graph/generated"
)
const defaultPort = "4001"
func main() {
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
http.Handle("/", playground.Handler("GraphQL playground", "/graphql"))
http.Handle("/graphql", srv)
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}