对象内部的对象本身将被一个空字段解析。
输入:
chrome://crashes/
输出:
{
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": {}
}
]
}
}
}
SalesHistory类型:
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,
},
},
})
在“解析返回”界面中的地图中:
map [data:[map [product_id:35 product_name:testpr sales_history:map [total_check:671.20]]]]
我自己创建地图“ sales_history”,否则在字段sales_history对面-空
答案 0 :(得分:0)
问题出在最终地图的包装中。
错了:
tmp := make(map[string]interface{}, 0)
tmp["total_check"] = v["total_check"]
v["sales_history"] = tmp
*某些字段被隐藏
那是正确的:
v["sales_history"] = make(map[string]interface{}, 0)
v["sales_history"].(map[string]interface{})["total_check"] = v["total_check"]