-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
45 lines (35 loc) · 1.11 KB
/
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
40
41
42
43
44
45
package main
import (
"log"
"net/http"
"os"
"strconv"
"github.com/marklude/go-sovtech/dataloader"
"github.com/marklude/go-sovtech/directives"
"github.com/marklude/go-sovtech/graph"
"github.com/marklude/go-sovtech/graph/generated"
"github.com/spf13/viper"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
)
const defaultPort = "8080"
func main() {
viper.SetConfigFile("config.yml")
err := viper.ReadInConfig()
if err != nil {
log.Fatalf("Error while reading config file %s", err)
os.Exit(1)
}
port := strconv.Itoa(viper.Get("go-sovtech.server.port").(int))
if port == "" {
port = defaultPort
}
c := generated.Config{Resolvers: &graph.Resolver{}}
c.Directives.IsAuthenticated = directives.Authenticate
srv := handler.NewDefaultServer(generated.NewExecutableSchema(c))
router := http.NewServeMux()
router.Handle("/", playground.Handler("GraphQL playground", "/query"))
router.Handle("/query", srv)
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, dataloader.Middleware(router)))
}