UNPKG

900 BJavaScriptView Raw
1import get from 'lodash.get';
2import { useQuery } from '@apollo/react-hooks';
3import throwErrorInDev from '../helpers/throwErrorInDev';
4/**
5 * Takes in the orderHeaders query and optional query variables, and returns
6 * the result and some helpers
7 */
8export default function useCustomerOrdersQuery({ query, variables }) {
9 const result = useQuery(query, { variables });
10 throwErrorInDev(!result.loading && !get(result, 'data.customer.orderHeaders'), 'Double-check that your query includes `{ customer { orderHeaders } }`');
11 const orders = get(result, 'data.customer.orderHeaders.result', []);
12 const totalOrders = get(result, 'data.customer.orderHeaders.totalResults');
13 return {
14 // Default loading to true for SSR
15 loading: result ? result.loading : true,
16 orders,
17 result,
18 totalOrders
19 };
20}
21//# sourceMappingURL=useCustomerOrdersQuery.js.map
\No newline at end of file