试图让嵌套数据downloads.copy
在页面上呈现。我使用 Apollo 客户端开发工具查看数据,但不会呈现到页面。我已经搜索了 apollo-link-rest 问题。我确定这是一些语法问题 - 或者不是。任何帮助/见解将不胜感激。
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",
}
]
},
]
}