package api import ( "time" "github.com/graphql-go/graphql" ) type Collect struct { ID int `json:"id" gorm:"primaryKey"` UserId int `json:"user_id"` ArticleId int `json:"article_id"` CreateTime time.Time `json:"create_time"` UpdateTime time.Time `json:"update_time"` } func (Collect) TableName() string { return "web_collect" } var CollectItems = &graphql.Field{ Name: "collects", Description: "收藏列表", Type: graphql.NewObject(graphql.ObjectConfig{ Name: "CollectConnection", Description: "条件筛选收藏列表", Fields: graphql.Fields{ "list": &graphql.Field{Type: graphql.NewList(graphql.NewObject(graphql.ObjectConfig{ Name: "Collect", Description: "收藏", Fields: graphql.Fields{ "id": &graphql.Field{Type: graphql.Int, Description: "收藏ID"}, "title": &graphql.Field{Type: graphql.String, Description: "收藏标题"}, "type": &graphql.Field{Type: graphql.Int, Description: "收藏类型"}, "create_time": &graphql.Field{Type: graphql.DateTime, Description: "收藏创建时间"}, "update_time": &graphql.Field{Type: graphql.DateTime, Description: "收藏更新时间"}, "praise_count": &graphql.Field{Type: graphql.Int, Description: "点赞数"}, "collect_count": &graphql.Field{Type: graphql.Int, Description: "收藏数"}, "praise": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否点赞"}, "collect": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否收藏"}, }, })), Description: "收藏列表"}, "total": &graphql.Field{Type: graphql.Int, Description: "收藏总数"}, }, }), Args: graphql.FieldConfigArgument{ "id": &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选收藏中指定ID的"}, "title": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选收藏中含有指定标题的"}, "type": &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选收藏中含有指定类型的"}, "create_time": &graphql.ArgumentConfig{Type: graphql.DateTime, Description: "筛选收藏中创建时间等于指定值的"}, "update_time": &graphql.ArgumentConfig{Type: graphql.DateTime, Description: "筛选收藏中更新时间等于指定值的"}, "first": &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的前n個元素)"}, "last": &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的最後n個元素)"}, "after": &graphql.ArgumentConfig{Type: graphql.String, Description: "翻页参数(傳回清單中指定遊標之後的元素)"}, "before": &graphql.ArgumentConfig{Type: graphql.String, Description: "翻页参数(傳回清單中指定遊標之前的元素)"}, }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { var collects []Collect var total int return map[string]interface{}{ "list": collects, "total": total, }, nil }, }