-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (63 loc) · 1.23 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
68
69
70
package main
import (
"net/http"
"github.com/rigglo/gql"
"github.com/rigglo/gql/pkg/handler"
)
type Pizza struct {
ID int `json:"id"`
Name string `json:"name"`
Size int `json:"size"`
}
var PizzaType = &gql.Object{
Name: "Pizza",
Fields: gql.Fields{
"id": &gql.Field{
Description: "id of the pizza",
Type: gql.ID,
},
"name": &gql.Field{
Description: "name of the pizza",
Type: gql.String,
},
"size": &gql.Field{
Description: "size of the pizza (in cm)",
Type: gql.Int,
},
},
}
var RootQuery = &gql.Object{
Name: "RootQuery",
Fields: gql.Fields{
"pizzas": &gql.Field{
Description: "lists all the pizzas",
Type: gql.NewList(PizzaType),
Resolver: func(ctx gql.Context) (interface{}, error) {
return []Pizza{
Pizza{
ID: 1,
Name: "Veggie",
Size: 32,
},
Pizza{
ID: 2,
Name: "Salumi",
Size: 45,
},
}, nil
},
},
},
}
var PizzeriaSchema = &gql.Schema{
Query: RootQuery,
}
func main() {
http.Handle("/graphql", handler.New(handler.Config{
Executor: gql.DefaultExecutor(PizzeriaSchema),
Playground: true,
}))
if err := http.ListenAndServe(":9999", nil); err != nil {
panic(err)
}
}