-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment.go
42 lines (35 loc) · 965 Bytes
/
comment.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 _ CommentService = (*commentService)(nil)
type CommentService interface {
Comments(p graphql.ResolveParams) (interface{}, error)
Comment(p graphql.ResolveParams) (interface{}, error)
}
var commentType = graphql.NewObject(graphql.ObjectConfig{
Name: "Comment",
Fields: graphql.Fields{
"postId": &graphql.Field{
Type: graphql.Int,
},
"id": &graphql.Field{
Type: graphql.Int,
},
"name": &graphql.Field{
Type: graphql.String,
},
"email": &graphql.Field{
Type: graphql.String,
},
"body": &graphql.Field{
Type: graphql.String,
},
}},
)
type commentService struct{ *Resolver }
func (c *commentService) Comments(p graphql.ResolveParams) (interface{}, error) {
return c.Client.Comment.List(p.Context)
}
func (c *commentService) Comment(p graphql.ResolveParams) (interface{}, error) {
input := uint64(p.Args["id"].(int))
return c.Client.Comment.Get(p.Context, input)
}