-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.go
52 lines (41 loc) · 1.41 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
46
47
48
49
50
51
52
// GraphQL Schema registry is used for discovery of services and keeps the schema of the gateway in sync
// with the service schemas it consumes, by automatically pushing schema changes.
package main
import (
"log"
"net/http"
"os"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/basselalaraaj/graphql-schema-registry/graph"
"github.com/basselalaraaj/graphql-schema-registry/graph/generated"
"github.com/basselalaraaj/graphql-schema-registry/registry"
"github.com/basselalaraaj/graphql-schema-registry/servicebus"
"github.com/joho/godotenv"
)
const defaultPort = "8080"
func loadConfig() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
}
func main() {
loadConfig()
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
if err := servicebus.ServiceBusClient.CreateClient(); err != nil {
panic(err)
}
registry.RedisDB.CreateRedisClient()
registry.MongoDB.CreateCollection()
srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
srv.Use(extension.Introspection{})
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))
}