-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (43 loc) · 1.24 KB
/
main.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
53
package main
import (
"context"
"log"
"net/http"
"github.com/nibbleshift/gorb/ent"
"github.com/nibbleshift/gorb/ent/migrate"
"github.com/nibbleshift/gorb/graph"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/go-chi/chi"
"github.com/rs/cors"
_ "github.com/lib/pq"
)
func main() {
router := chi.NewRouter()
// Add CORS middleware around every request
// See https://github.com/rs/cors for full option listing
router.Use(cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowCredentials: true,
Debug: false,
}).Handler)
// Create ent.Client and run the schema migration.
client, err := ent.Open("postgres", "user=postgres password=example dbname=gorb sslmode=disable")
if err != nil {
log.Fatal("opening ent client", err)
}
if err := client.Schema.Create(
context.Background(),
migrate.WithGlobalUniqueID(true),
); err != nil {
log.Fatal("opening ent client", err)
}
// Configure the server and start listening on :8081.
srv := handler.NewDefaultServer(graph.NewSchema(client))
router.Handle("/", playground.Handler("gorb", "/query"))
router.Handle("/query", srv)
err = http.ListenAndServe(":8081", router)
if err != nil {
panic(err)
}
}