I need to know why GraphQL nested queries aren't working specifically while using react-table. I'm trying to render a table, and one of my columns, Item Count, isn't displaying specifically because the query is nested.
GET_SHIPMENTS query:
export const GET_SHIPMENTS = gql`
{
shipments {
created_at
id
status
orders {
order_items
}
}
}
`;
I've gone onto the spectrum chat located here -> https://spectrum.chat/react-table?tab=posts and have had no luck with what they have offered. The original solution was to map over an array and define entry points for the schema to display properly.
Example:
data={data.shipments.map((entry, index) => {
{
id: entry.id,
status: entry.status,
order_items: entry.orders.order_items
}
)}
This gave me an unexpected token error, which I cannot resolve.
My React Table is being rendered with a HOC to display data from my shipments query.
import { graphql } from 'react-apollo';
import { GET_SHIPMENTS } from '../graphql/ShipmentQueries';
import ReactTable from 'react-table';
import {
Card,
CardBody,
Row,
} from "reactstrap";
function OrderTable ({ loading, shipments }) {
const columns = [
{
Header: 'ID',
accessor: 'id',
},
{
Header: 'Status',
accessor: 'status',
},
{
Header: 'Item Count',
accessor: 'order_items',
},
{
Header: 'Time Stamp',
accessor: 'created_at',
},
];
if (loading) return <p>Loading...</p>;
return (
<div className="content">
<Row className="mt-5">
<Card>
<CardBody>
<ReactTable
data={shipments}
columns={columns}
sortable={true}
resizable={false}
minRows={10}
/>
</CardBody>
</Card>
</Row>
</div>
);
}
export const OrderTableWithData = graphql(GET_SHIPMENTS, {
props: ({data: { loading, shipments }}) => ({
loading,
shipments,
}),
})(OrderTable);
The data from order_item is not displaying, so I'm wondering how to resolve this issue so this information can be displayed in my table. I cannot edit the schema.