我在这里遇到了一个富查询和对流链代码的问题,一切都适用于芒果查询,但当我传递content对象时,它是stringifyed,不会被发送有一个对象,但被转换为字符串"content":"{\"data\":\"1971\"}",显然它无法通过查询
原始示例查询
{
"selector": {
"type": "io.worldsibu.examples.person",
"attributes": {
"$elemMatch": {
"id": "born-year",
"content": {
"data": "1971"
}
}
}
}
}graphql查询变量
{
"getByAttributeInput": {
"id": "born-year",
"content": {
"data": "1971"
}
},
"skip": 0,
"take": 10
}packages/person-cc/src/person.controller.ts
链码控制器方法
@Invokable()
public async getByAttribute(
@Param(yup.string())
id: string,
@Param(yup.mixed())
value: any
) {
return await Person.query(Person, {
selector: {
type: c.CONVECTOR_MODEL_PATH_PERSON,
attributes: {
$elemMatch: {
id: id,
content: value
}
}
}
});
}在docker日志中,我们可以看到值是发送的内容是一个字符串,而不是"content":"{\"data\":\"1971\"}"以外的对象
{"selector":{"type":"io.worldsibu.examples.person","attributes":{"$elemMatch":{"id":"born-year","content":"{\"data\":\"1971\"}"}}}}发布于 2019-09-08 07:23:57
诀窍是将@Param(yup.mixed())更改为@Param(yup.object()),现在它可以像预期的那样工作,我们可以用任意和复杂的对象查询属性内容值
@Invokable()
public async getByAttribute(
@Param(yup.string())
id: string,
// @Param(yup.mixed())
@Param(yup.object())
value: any
) {
...https://stackoverflow.com/questions/57838092
复制相似问题