【发布时间】:2019-01-25 06:40:31
【问题描述】:
我正在尝试直接在我的 React 组件中传递我的 GraphQL 查询的变量。
到目前为止,我已尝试通过它:
- 直接在 this.props.mutate 中
- 在 client.props 中
- 在我的父组件中作为
- 查看 React.clone
- 在client.query中
它们都不起作用,也许我忘记了什么。
目前我必须在选项中对其进行硬编码,但它使我无法动态编码:
export default graphql(fetchRecipe,
{options: (props) => ({
variables: { }
})})(Displayer);
* 解决方法尝试但失败:消失模式如下:*
import {...}
var property; // just declare your property
class YourClass extends Component {
property = newValue // your property is now available on the Component's scope,
// allowing you to code it dynamically
render(){ {...}
}
export default graphql(query,
{options: (props) => ({
variables: { property } // hence pass the value you want in your graphql options's property
})})(YourClass);
所以我还是在寻找如何直接在组件中传递,任何提示都会很棒,
谢谢,
【问题讨论】:
标签: reactjs graphql apollo react-apollo apollo-client