Prevent endless limit refetching (#1059)
* Fix endless limit refresh loop * Improve naming
This commit is contained in:
parent
9362ea53b0
commit
07bc522af1
3 changed files with 32 additions and 16 deletions
|
@ -1,5 +1,5 @@
|
|||
import { limitFragment } from "@saleor/fragments/shop";
|
||||
import makeQuery from "@saleor/hooks/makeQuery";
|
||||
import makeQuery, { UseQueryOpts } from "@saleor/hooks/makeQuery";
|
||||
import gql from "graphql-tag";
|
||||
|
||||
import { TypedQuery } from "../../queries";
|
||||
|
@ -39,21 +39,37 @@ const shopInfo = gql`
|
|||
`;
|
||||
export const TypedShopInfoQuery = TypedQuery<ShopInfo, {}>(shopInfo);
|
||||
|
||||
const limitVariables: Record<keyof RefreshLimitsVariables, boolean> = {
|
||||
channels: false,
|
||||
orders: false,
|
||||
productVariants: false,
|
||||
staffUsers: false,
|
||||
warehouses: false
|
||||
};
|
||||
const limitInfo = gql`
|
||||
${limitFragment}
|
||||
query RefreshLimits(
|
||||
$channels: Boolean = false
|
||||
$orders: Boolean = false
|
||||
$productVariants: Boolean = false
|
||||
$staffUsers: Boolean = false
|
||||
$warehouses: Boolean = false
|
||||
$channels: Boolean!
|
||||
$orders: Boolean!
|
||||
$productVariants: Boolean!
|
||||
$staffUsers: Boolean!
|
||||
$warehouses: Boolean!
|
||||
) {
|
||||
shop {
|
||||
...ShopLimitFragment
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const useShopLimitsQuery = makeQuery<
|
||||
RefreshLimits,
|
||||
RefreshLimitsVariables
|
||||
>(limitInfo);
|
||||
const useBaseShopLimitsQuery = makeQuery<RefreshLimits, RefreshLimitsVariables>(
|
||||
limitInfo
|
||||
);
|
||||
export const useShopLimitsQuery = (
|
||||
opts: UseQueryOpts<Partial<RefreshLimitsVariables>>
|
||||
) =>
|
||||
useBaseShopLimitsQuery({
|
||||
...opts,
|
||||
variables: {
|
||||
...limitVariables,
|
||||
...opts.variables
|
||||
}
|
||||
});
|
||||
|
|
|
@ -41,9 +41,9 @@ export interface RefreshLimits {
|
|||
}
|
||||
|
||||
export interface RefreshLimitsVariables {
|
||||
channels?: boolean | null;
|
||||
orders?: boolean | null;
|
||||
productVariants?: boolean | null;
|
||||
staffUsers?: boolean | null;
|
||||
warehouses?: boolean | null;
|
||||
channels: boolean;
|
||||
orders: boolean;
|
||||
productVariants: boolean;
|
||||
staffUsers: boolean;
|
||||
warehouses: boolean;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ export interface LoadMore<TData, TVariables> {
|
|||
|
||||
export type UseQueryResult<TData, TVariables> = QueryResult<TData, TVariables> &
|
||||
LoadMore<TData, TVariables>;
|
||||
type UseQueryOpts<TVariables> = Partial<{
|
||||
export type UseQueryOpts<TVariables> = Partial<{
|
||||
displayLoader: boolean;
|
||||
skip: boolean;
|
||||
variables: TVariables;
|
||||
|
|
Loading…
Reference in a new issue