Add optional fields for articles and users

This commit is contained in:
2023-11-21 00:08:29 +08:00
parent bd260ed4d6
commit f3c7441b11

View File

@@ -28,6 +28,7 @@ func init() {
func NewSchema() (graphql.Schema, error) { func NewSchema() (graphql.Schema, error) {
// 文章的可选字段
article := graphql.NewObject(graphql.ObjectConfig{ article := graphql.NewObject(graphql.ObjectConfig{
Name: "Article", Name: "Article",
Fields: graphql.Fields{ Fields: graphql.Fields{
@@ -39,6 +40,7 @@ func NewSchema() (graphql.Schema, error) {
}, },
}) })
// 用户的可选字段
user := graphql.NewObject(graphql.ObjectConfig{ user := graphql.NewObject(graphql.ObjectConfig{
Name: "User", Name: "User",
Fields: graphql.Fields{ Fields: graphql.Fields{
@@ -52,6 +54,7 @@ func NewSchema() (graphql.Schema, error) {
}, },
}) })
// 用户列表查询
users := &graphql.Field{ users := &graphql.Field{
Type: graphql.NewList(user), Type: graphql.NewList(user),
Args: graphql.FieldConfigArgument{ Args: graphql.FieldConfigArgument{