-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.go
48 lines (43 loc) · 1.06 KB
/
schema.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
package main
import (
"github.com/graphql-go/graphql"
"log"
)
func CreateSchema() graphql.Schema {
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "Root",
Fields: graphql.Fields{
"get_product": &graphql.Field{
Name: "GetProduct",
Type: ProductObject,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
product := getProduct()
return product, nil
},
},
"get_product_by_id": &graphql.Field{
Name: "GetProductById",
Type: ProductObject,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
productID := p.Args["product_id"].(int)
product := getProductByID(productID)
return product, nil
},
},
"get_products": &graphql.Field{
Name: "GetProducts",
Type: graphql.NewList(ProductObject),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
product := getProducts()
return product, nil
},
},
},
}),
})
if err != nil {
log.Fatal(err)
}
return schema
}