UNPKG

1.42 kBJavaScriptView Raw
1import { useQuery } from '@apollo/react-hooks';
2import throwErrorInDev from '../helpers/throwErrorInDev';
3import logWarningInDev from '../helpers/logWarningInDev';
4/**
5 * Takes in the orderDetails query and order id, and returns the result and
6 * some helpers
7 */
8export default function useOrderDetailQuery({ query, id }) {
9 var _a, _b;
10 const queryUsesOrderIdParam =
11 // @ts-ignore
12 ((_b = (_a = query.definitions[0]) === null || _a === void 0 ? void 0 : _a.variableDefinitions[0]) === null || _b === void 0 ? void 0 : _b.variable.name.value) ===
13 'orderId';
14 const result = useQuery(query, {
15 variables: queryUsesOrderIdParam ? { orderId: id } : { id: id }
16 });
17 throwErrorInDev(!!result.error, `The API returned an error for the Order query with id ${id}.
18 ${result.error}`);
19 logWarningInDev(!queryUsesOrderIdParam, 'order(id: Int) has been deprecated. Please update OrderDetail.gql to use the orderId variable.');
20 throwErrorInDev(!result.loading && result.data && !result.data.order ? true : false, 'No order field was found in the response. Double-check that your query includes `{ order(orderId: ID!) }`');
21 return {
22 // Default loading to true for SSR
23 loading: result ? result.loading : true,
24 error: result.error,
25 order: result.data ? result.data.order : null,
26 result
27 };
28}
29//# sourceMappingURL=useOrderDetailQuery.js.map
\No newline at end of file