Graphene-django - 如何捕获查询的响应?

Graphene-django - How to catch response of query?

我使用 django 和 django graphene 制作 graphql API。

在我的应用视图中,我使用了reactJS和react-bootstrap-table. React-bootstrap-table expects that I pass it an object array but does not support nested objects

我在 schema.py:

中创建了查询
class ApplicationNode(DjangoObjectType):
    class Meta:
        model = Application
        filter_fields = ['name', 'sonarQube_URL']
        interfaces = (relay.Node,)

class Query(ObjectType):
    application = relay.Node.Field(ApplicationNode)
    all_applications = DjangoFilterConnectionField(ApplicationNode)

这些查询的答案是 JSON 嵌套对象,如下所示:

{
  "data": {
    "allApplications": {
      "edges": [
        {
          "node": {
            "id": "QXBwbGljYXRpb25Ob2RlOjE=",
            "name": "foo",
            "sonarQubeUrl": "foo.com",
            "flow":{ 
                "id": "QYBwbGljYXRpb45Ob2RlOjE=",
                "name": "flow_foo"
            }
          }
        },
        {
          "node": {
            "id": "QXBwbGljYXRpb25Ob2RlOjI=",
            "name": "bar",
            "sonarQubeUrl": "bar.com"
            "flow":{ 
                "id": "QXBwbGljYXRpb26Ob2RlOjA=",
                "name": "flow_bar"
            }
          }
        }
      ]
    }
  }
}

在给 React 之前我必须把它们放平-bootstrap-table.

什么是更好的方法,拦截 graphene-django 查询的结果以将它们平放或在 ReactJS 视图中完成这项工作?

如果第一种方式更好,如何截取graphene-django查询的结果放平?

最好的办法是将 react-bootstrap-table 包装在一个新组件中。在组件中,根据需要将中继道具按摩成扁平结构以进行反应 bootstrap table.

例如:

MyReactTable = ({allApplications}) => {
  let flatApplications = allApplications.edges.map(({node: app}) => {
    return {
      name: app.name,
      sonarQubeUrl: app.sonarQubeUrl,
      flowName: app.flow.name
    };
  });
  return (
    <BootstrapTable data={flatApplications} striped={true} hover={true}>
      <TableHeaderColumn dataField="name" isKey={true} dataAlign="center" dataSort={true}>Name</TableHeaderColumn>
      <TableHeaderColumn dataField="sonarQubeUrl" dataSort={true}>Sonar Qube Url</TableHeaderColumn>
      <TableHeaderColumn dataField="flowName" dataFormat={priceFormatter}>Flow Name</TableHeaderColumn>
    </BootstrapTable>
  );
};