支持单图查询

This commit is contained in:
2024-11-07 02:23:52 +08:00
parent cd1db1b82a
commit 9fa5007ac4

View File

@@ -629,6 +629,22 @@ func NewSchema(config Config) (graphql.Schema, error) {
}, nil
},
},
"image": &graphql.Field{
Name: "image",
Description: "单张图片",
Type: image,
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{Type: graphql.Int, Description: "根据ID获取图片"},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
img := Image{ID: p.Args["id"].(int)}
if err := db.First(&img).Error; err != nil {
log.Println("获取图片失败", err)
return nil, err
}
return img, nil
},
},
}})})
if err != nil {
return schema, err