对象内部的对象本身被解析为一个空字段。
输入:
{
Products(search: {limit: 1, filters: {product_id: {gte: 5}}}) {
data {
product_id
product_name
sales_history{
total_check
}
}
}
}
输出:
{
"data": {
"Products": {
"data": [
{
"product_id": 35,
"product_name": "testpr",
"sales_history": {}
}
]
}
}
}
产品类别:
gql.ProductType = graphql.NewObject(graphql.ObjectConfig{
Name: "Product",
Fields: graphql.Fields{
"product_id": &graphql.Field{
Type: graphql.Int,
},
"product_name": &graphql.Field{
Type: graphql.String,
},
"sales_history": &graphql.Field{
Type: gql.SalesHistoryType,
},
},
})
销售历史类型:
gql.SalesHistoryType = graphql.NewObject(graphql.ObjectConfig{
Name: "sales_history",
Fields: graphql.Fields{
"total_check": &graphql.Field{
Type: graphql.Float,
},
},
})
在 Resolve 在界面中返回地图:
地图[数据:[地图[product_id:35 product_name:testpr sales_history:map[total_check:671.20]]]]
我自己创建地图“sales_history”,否则与字段 sales_history - null