-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
39 lines (29 loc) · 843 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
30
31
32
33
34
35
36
37
38
39
package main
import (
"log"
"net/http"
"os"
"parts/graph"
"parts/graph/generated"
"parts/service"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/joho/godotenv"
)
const defaultPort = "8080"
func main() {
godotenv.Load()
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
svc, err := service.Create()
if err != nil {
panic(err)
}
srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{Svc: svc}}))
http.Handle("/", playground.Handler("GraphQL playground", "/query"))
http.Handle("/query", srv)
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, nil /* handlers.CombinedLoggingHandler(os.Stdout, http.DefaultServeMux)*/))
}