[英]How to pass data from multiple collections in mongodb to 1 react table using graphql
I have a react-table that I'm passing data through graphql queries. 我有一个反应表,我正在通过graphql查询传递数据。 but my query has relationships with different objects within the database collections.
但是我的查询与数据库集合中的不同对象有关系。 When I pass the data I only get data from one collection.
当我传递数据时,我只能从一个集合中获取数据。
Here's my query --- 这是我的查询-
const getBikesQuery = gql`
{
AllBikeEntries{
bikenumber
distributedyear
ProjectName{
projectname
}
}
}
`;
my table only displays data from bikenumber
and distributedyear
. 我的表格仅显示来自
bikenumber
和distributedyear
数据。
here's the rest of the code. 这是其余的代码。
const columns = [
{
Header: "Number of Bikes",
accessor: "bikenumber"
},
{
Header: "Season",
accessor: "distributedyear"
},
{
Header: "Project",
accessor: "projectname"
}
];
class Entries extends Component {
render() {
let {data} = this.props;
console.log(data)
return(
<div>
<ReactTable
data ={data.AllBikeEntries}
columns ={columns}
defaultPageSize={10}
/>
</div>
);
}
}
export default graphql(getBikesQuery)(Entries);
the accessor for projectname
cant be read, and I have other more complicated queries that I cant render. 无法读取
projectname
的访问器,而我还有其他更复杂的查询无法渲染。 what's the best way to go about this problem?? 解决此问题的最佳方法是什么?
And just to add the data I need is logged on the console 只需添加我需要的数据就记录在控制台上
AllBikeEntries: Array(2)
0:
ProjectName: {projectname: "INVC", __typename: "Projects", Symbol(id):
"$ROOT_QUERY.AllBikeEntries.0.ProjectName"}
bikenumber: 20
distributedyear: 2015
__typename: "Bikes"
Symbol(id): "ROOT_QUERY.AllBikeEntries.0"
__proto__: Object
1:
ProjectName: {projectname: "INVC", __typename: "Projects", Symbol(id):
"$ROOT_QUERY.AllBikeEntries.1.ProjectName"}
bikenumber: 35
distributedyear: 2016
__typename: "Bikes"
Mongo and GraphQL are only source of structured data. Mongo和GraphQL只是结构化数据的来源。 Data is fetched (as logged) properly, you have a problem with rendering tree structured data.
正确提取(记录)数据时,呈现树状结构数据存在问题。
Just read react-table
docs, look at examples, fe this one ... you should use accessor
to get access to the right parts of data. 只需阅读
react-table
文档,看看示例,例如这 ……您应该使用accessor
来访问数据的正确部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.