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 { limitFragment } from "@saleor/fragments/shop";
|
||||||
import makeQuery from "@saleor/hooks/makeQuery";
|
import makeQuery, { UseQueryOpts } from "@saleor/hooks/makeQuery";
|
||||||
import gql from "graphql-tag";
|
import gql from "graphql-tag";
|
||||||
|
|
||||||
import { TypedQuery } from "../../queries";
|
import { TypedQuery } from "../../queries";
|
||||||
|
@ -39,21 +39,37 @@ const shopInfo = gql`
|
||||||
`;
|
`;
|
||||||
export const TypedShopInfoQuery = TypedQuery<ShopInfo, {}>(shopInfo);
|
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`
|
const limitInfo = gql`
|
||||||
${limitFragment}
|
${limitFragment}
|
||||||
query RefreshLimits(
|
query RefreshLimits(
|
||||||
$channels: Boolean = false
|
$channels: Boolean!
|
||||||
$orders: Boolean = false
|
$orders: Boolean!
|
||||||
$productVariants: Boolean = false
|
$productVariants: Boolean!
|
||||||
$staffUsers: Boolean = false
|
$staffUsers: Boolean!
|
||||||
$warehouses: Boolean = false
|
$warehouses: Boolean!
|
||||||
) {
|
) {
|
||||||
shop {
|
shop {
|
||||||
...ShopLimitFragment
|
...ShopLimitFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
export const useShopLimitsQuery = makeQuery<
|
const useBaseShopLimitsQuery = makeQuery<RefreshLimits, RefreshLimitsVariables>(
|
||||||
RefreshLimits,
|
limitInfo
|
||||||
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 {
|
export interface RefreshLimitsVariables {
|
||||||
channels?: boolean | null;
|
channels: boolean;
|
||||||
orders?: boolean | null;
|
orders: boolean;
|
||||||
productVariants?: boolean | null;
|
productVariants: boolean;
|
||||||
staffUsers?: boolean | null;
|
staffUsers: boolean;
|
||||||
warehouses?: boolean | null;
|
warehouses: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ export interface LoadMore<TData, TVariables> {
|
||||||
|
|
||||||
export type UseQueryResult<TData, TVariables> = QueryResult<TData, TVariables> &
|
export type UseQueryResult<TData, TVariables> = QueryResult<TData, TVariables> &
|
||||||
LoadMore<TData, TVariables>;
|
LoadMore<TData, TVariables>;
|
||||||
type UseQueryOpts<TVariables> = Partial<{
|
export type UseQueryOpts<TVariables> = Partial<{
|
||||||
displayLoader: boolean;
|
displayLoader: boolean;
|
||||||
skip: boolean;
|
skip: boolean;
|
||||||
variables: TVariables;
|
variables: TVariables;
|
||||||
|
|
Loading…
Reference in a new issue