-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.go
42 lines (35 loc) · 966 Bytes
/
post.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
package main
import "github.com/graphql-go/graphql"
var _ PostService = (*postService)(nil)
type PostService interface {
Posts(p graphql.ResolveParams) (interface{}, error)
Post(p graphql.ResolveParams) (interface{}, error)
}
var postType = graphql.NewObject(graphql.ObjectConfig{
Name: "Post",
Fields: graphql.Fields{
"userId": &graphql.Field{
Type: graphql.Int,
},
"id": &graphql.Field{
Type: graphql.Int,
},
"title": &graphql.Field{
Type: graphql.String,
},
"body": &graphql.Field{
Type: graphql.String,
},
"comments": &graphql.Field{
Type: graphql.NewList(commentType),
},
}},
)
type postService struct{ *Resolver }
func (p *postService) Posts(params graphql.ResolveParams) (interface{}, error) {
return p.Client.Post.List(params.Context)
}
func (p *postService) Post(params graphql.ResolveParams) (interface{}, error) {
input := uint64(params.Args["id"].(int))
return p.Client.Post.Get(params.Context, input)
}