-
Notifications
You must be signed in to change notification settings - Fork 1
/
zan.go
51 lines (48 loc) · 1.74 KB
/
zan.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
package controller
import "github.com/graphql-go/graphql"
var objtype = graphql.NewEnum(graphql.EnumConfig{
Name: "Objtype",
Values: graphql.EnumValueConfigMap{
"article": {Value: "article", Description: "文章"},
"comment": {Value: "comment", Description: "评论"},
"reply": {Value: "reply", Description: "回复"},
},
Description: "对象类型",
})
var zanType = graphql.NewObject(graphql.ObjectConfig{
Name: "Zan",
Fields: graphql.Fields{
"id": {Type: graphql.NewNonNull(graphql.ID), Description: "ID"},
"uid": {Type: graphql.NewNonNull(graphql.ID), Description: "点赞用户ID"},
"objtype": {Type: graphql.NewNonNull(objtype), Description: "被点赞对象类型"},
"objid": {Type: graphql.NewNonNull(graphql.ID), Description: "被点赞对象ID"},
},
Description: "点赞",
})
var zanListField = graphql.Field{
Name: "zanList",
Type: graphql.NewList(zanType),
Args: graphql.FieldConfigArgument{
"objtype": {Type: graphql.NewNonNull(objtype), Description: "被点赞对象类型"},
"objid": {Type: graphql.NewNonNull(graphql.ID), Description: "被点赞对象ID"},
},
Resolve: nil,
Description: "赞列表",
}
func registerZanType() {
mutationType.AddFieldConfig("Zan", &graphql.Field{
Type: zanType,
Args: graphql.FieldConfigArgument{
"objtype": {Type: graphql.NewNonNull(objtype), Description: "被点赞对象类型"},
"objid": {Type: graphql.NewNonNull(graphql.ID), Description: "被点赞对象ID"},
},
Resolve: nil,
Description: "点赞",
})
mutationType.AddFieldConfig("CancelZan", &graphql.Field{
Type: graphql.Boolean,
Args: graphql.FieldConfigArgument{"id": {Type: graphql.NewNonNull(graphql.ID), Description: "ID"}},
Resolve: nil,
Description: "点赞",
})
}