处理字段

This commit is contained in:
2023-11-30 05:23:01 +08:00
parent 72853f7a7f
commit fa2af13e96
4 changed files with 59 additions and 14 deletions

View File

@@ -93,6 +93,7 @@ func NewSchema() (graphql.Schema, error) {
"rank": &graphql.ArgumentConfig{Type: graphql.String},
"create_time": &graphql.ArgumentConfig{Type: graphql.DateTime},
"update_time": &graphql.ArgumentConfig{Type: graphql.DateTime},
"text": &graphql.ArgumentConfig{Type: graphql.String}, // 查找图像中的文字
"first": &graphql.ArgumentConfig{Type: graphql.Int, DefaultValue: 10}, // 翻页参数
"after": &graphql.ArgumentConfig{Type: graphql.String, DefaultValue: "0"}, // 翻页参数
},
@@ -102,17 +103,20 @@ func NewSchema() (graphql.Schema, error) {
for _, field := range requestedFields {
fieldAST, ok := field.(*ast.Field)
if ok {
if fieldAST.Name.Value == "list" {
switch fieldAST.Name.Value {
case "list":
for _, field := range fieldAST.SelectionSet.Selections {
fieldAST, ok := field.(*ast.Field)
if ok {
fields = append(fields, fieldAST.Name.Value)
}
}
} else if fieldAST.Name.Value == "next" {
case "next":
fmt.Println("next")
} else {
fields = append(fields, fieldAST.Name.Value)
case "text":
fmt.Println("text")
default:
fmt.Println(fieldAST.Name.Value)
}
}
}
@@ -194,23 +198,25 @@ func NewSchema() (graphql.Schema, error) {
for _, field := range requestedFields {
fieldAST, ok := field.(*ast.Field)
if ok {
if fieldAST.Name.Value == "list" {
switch fieldAST.Name.Value {
case "list":
for _, field := range fieldAST.SelectionSet.Selections {
fieldAST, ok := field.(*ast.Field)
if ok {
if fieldAST.Name.Value == "user" {
switch fieldAST.Name.Value {
case "user":
fields = append(fields, "user_id")
} else if fieldAST.Name.Value == "article" {
case "article":
fields = append(fields, "article_id")
} else {
default:
fields = append(fields, fieldAST.Name.Value)
}
}
}
} else if fieldAST.Name.Value == "next" {
case "next":
fmt.Println("next")
} else {
fields = append(fields, fieldAST.Name.Value)
default:
fmt.Println(fieldAST.Name.Value)
}
}
}