-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (50 loc) · 1.38 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"github.com/makinap/osu/config"
"github.com/makinap/osu/directives"
"github.com/makinap/osu/middlewares"
"github.com/makinap/osu/migration"
"log"
"net/http"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
_ "github.com/jinzhu/gorm/dialects/postgres"
"github.com/makinap/osu/graph"
"github.com/makinap/osu/graph/generated"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
func main() {
migration.MigrateTable()
db := config.GetDB()
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middlewares.AuthMiddleware)
e.GET("/", welcome())
c := generated.Config{Resolvers: &graph.Resolver{DB: db}}
c.Directives.Auth = directives.Auth
graphqlHandler := handler.NewDefaultServer(
generated.NewExecutableSchema( c,
//generated.Config{Resolvers: &graph.Resolver{DB: db}},
),
)
playgroundHandler := playground.Handler("GraphQL", "/query")
e.POST("/query", func(c echo.Context) error {
graphqlHandler.ServeHTTP(c.Response(), c.Request())
return nil
})
e.GET("/playground", func(c echo.Context) error {
playgroundHandler.ServeHTTP(c.Response(), c.Request())
return nil
})
err := e.Start(":3000")
if err != nil {
log.Fatalln(err)
}
}
func welcome() echo.HandlerFunc {
return func(c echo.Context) error {
return c.String(http.StatusOK, "Welcome!")
}
}