-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
41 lines (33 loc) · 911 Bytes
/
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
package main
import (
"log"
"mime/multipart"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/mjarkk/yarql"
)
func main() {
app := fiber.New()
app.Use(cors.New())
schema := yarql.NewSchema()
err := schema.Parse(QueryRoot{}, MethodRoot{}, nil)
if err != nil {
log.Fatal(err)
}
app.All("/graphql", func(c *fiber.Ctx) error {
res, _ := schema.HandleRequest(
c.Method(),
func(key string) string { return c.Query(key) },
func(key string) (string, error) { return c.FormValue(key), nil },
func() []byte { return c.Body() },
string(c.Request().Header.ContentType()),
&yarql.RequestOptions{
GetFormFile: func(key string) (*multipart.FileHeader, error) { return c.FormFile(key) },
Tracing: true,
},
)
c.Response().Header.Set("Content-Type", "application/json")
return c.Send(res)
})
log.Fatal(app.Listen(":5500"))
}