小编Mik*_*ike的帖子

使用Apollo Client动态设置React组件的GraphQL查询

我正在构建一个React前端,它允许用户从静态查询列表中选择"活动"查询,并展平到要在表格中显示的结果.将GraphQL查询从更高阶组件传递到嵌套子组件的最佳方法是什么?

我见过的大多数文档/解决方案都侧重于将动态条件从组件状态绑定到组件的静态查询,这对我的目的不起作用,因为不同的静态查询具有不同的字段并查询不同的节点类型.

这里的最佳实践/推荐方法是什么?我觉得这不是一个非常独特的用例,但我似乎找不到任何类似的例子.

我使用Apollo-Client/Redux作为我的客户端商店.

以下是组件的粗略轮廓:

class GridViewPage extends React.Component{
  constructor(props, context) {
    super(props, context);
    this.state = {
      activeQuery = ... Stores the selected query ...
    };
  }

  render() {
    return (
      <div className="gridContainer">
        ...Component here allows users to select a query from active list and saves it/it's ID/Index to the state...

        <Panel collapsible>
        ...Some toolbar components...
        </Panel>
        ...Component here displays the result of the query (Ideally by receiving the query or the result of as a prop?)...
      </div>
    );
  } …
Run Code Online (Sandbox Code Playgroud)

reactjs graphql react-redux react-apollo

5
推荐指数
1
解决办法
3294
查看次数

标签 统计

graphql ×1

react-apollo ×1

react-redux ×1

reactjs ×1