无法使用 Apollo-link-rest 和 ReactJS 从数组中呈现嵌套对象

Can't render a nested object from an array with Apollo-link-rest and ReactJS

正在尝试获取要在页面上呈现的嵌套数据 downloads.copy。我使用 Apollo Client Dev Tools 查看数据,但不会呈现到页面。我搜索了 apollo-link-rest 问题。我确定这是一些语法问题 - 或者不是。任何 help/insight 将不胜感激。

import React, { Component } from "react";
import { graphql } from "react-apollo";
import gql from "graphql-tag";

const Query = gql`
  query tool {
    tools @rest(type: "ToolsPayload", path: "some-api/tools") {
      id
      headerTitle
      description
      downloads @type(name: "ToolsPayloadDownloads") {
        copy
      }
    }
  }
`;

class Tool extends Component {
  render() {
    const { loading, error, tools } = this.props;
    if (loading) {
      return <h4>Loading...</h4>;
    }
    if (error) {
      return <h4>{error.message}</h4>;
    }
    return (
      <div>
        {tools.map(tool => {
          return (
            <div key={tool.id}>
              <h1>{tool.headerTitle}</h1>
              // ** CAN'T GET THE DOWNLOADS COPY TO RENDER ** // 
              <h1>{tool.downloads.copy}</h1>
            </div>
          );
        })}
      </div>
    );
  }
}

export default graphql(Query, {
  props: ({ data }) => {
    if (data.loading) {
      return {
        loading: data.loading
      };
    }
    if (data.error) {
      return {
        error: data.error
      };
    }
    return {
      tools: data.tools,
      loading: false
    };
  }
})(Tool);

{
   [
      {
        "id": "1025",
        "headerTitle": "Title",
        "downloads": [
            {
                "id": "1234",
                "copy": "Some copy",

            }
        ]
    }, 
      {
        "id": "1026",
        "headerTitle": "Title2",
        "downloads": [
            {
                "id": "5678",
                "copy": "Some copy2",

            }
        ]
    },

  ]
}

downloads 是一个数组 - 使用 tool.downloads[0].copy

查询应在 downloads 中包含一个 id 字段 - 以正确缓存 ToolsPayloadDownloads 类型。

您可以使用 React 开发工具检查 this/inspect apollo 缓存 data/details。