我正在查询,并且已经记录了结果。一切正常,但是当我要继续处理结果时,它始终是“未定义的”(请参阅第二次日志记录)。 我敢肯定,我在这里缺少明显的东西,但真的很想得到您的帮助:)
$product = Product::where('slug', $slug)->firstOrFail();
$brand = $product->brands()->first(); //get the first brand
$brands = $product->brands; //get all brands for the product
$my_other_property = $product->properties()->where('identifier', 'my_other_property')->first(); //get first prop called 'my_other_property'
答案 0 :(得分:0)
如果children
给您正确的结果,您是否不仅可以将变量saved
分配给this.props.apolloClient
函数,并在subscribe
调用中返回子代?
类似的东西:
render() {
const saved = this.props.apolloClient
.watchQuery<Query>({
query: gql`
query($id: ID!) {
element(id: $id) {
children {
... on TextNote {
name
description
type
}
}
}
}
`,
variables: { id: 0 }
})
.subscribe(({ data: { element: { children } } }) => {
console.log(children); // this is the wanted result
return children; // <-- return the value here
});
console.log("save");
console.log(saved); // <-- should have children assigned to saved