From 6d61cd19578749afef935d9bdd865852b12bddbd Mon Sep 17 00:00:00 2001 From: Ivan Kalachikov Date: Wed, 18 Dec 2024 12:37:14 +0100 Subject: [PATCH 1/7] fix: cart refreshing issues --- client-app/core/api/graphql/cart/consts.ts | 1 + .../graphql/cart/mutations/addBulkItemsCart/index.ts | 12 ++---------- .../graphql/cart/mutations/addItemToCart/index.ts | 12 ++---------- .../api/graphql/cart/mutations/addItemsCart/index.ts | 12 ++---------- .../mutations/changeShortCartItemQuantity/index.ts | 12 ++---------- .../api/graphql/cart/queries/getShortCart/index.ts | 6 +----- client-app/pages/cart.vue | 2 +- 7 files changed, 11 insertions(+), 46 deletions(-) diff --git a/client-app/core/api/graphql/cart/consts.ts b/client-app/core/api/graphql/cart/consts.ts index 3d104545eb..b2cfba3614 100644 --- a/client-app/core/api/graphql/cart/consts.ts +++ b/client-app/core/api/graphql/cart/consts.ts @@ -14,6 +14,7 @@ export const FULL_CART_MUTATION_NAMES = [ OperationNames.Mutation.AddOrUpdateCartShipment, OperationNames.Mutation.ChangeCartComment, OperationNames.Mutation.ChangeFullCartItemQuantity, + OperationNames.Mutation.ChangeFullCartItemsQuantity, OperationNames.Mutation.ChangePurchaseOrderNumber, OperationNames.Mutation.ClearCart, OperationNames.Mutation.RejectGiftItems, diff --git a/client-app/core/api/graphql/cart/mutations/addBulkItemsCart/index.ts b/client-app/core/api/graphql/cart/mutations/addBulkItemsCart/index.ts index a7a9df0471..09c1c0a4da 100644 --- a/client-app/core/api/graphql/cart/mutations/addBulkItemsCart/index.ts +++ b/client-app/core/api/graphql/cart/mutations/addBulkItemsCart/index.ts @@ -1,19 +1,11 @@ -import { useApolloClient } from "@vue/apollo-composable"; import { useCartMutationVariables } from "@/core/api/graphql/cart/composables"; import { useMutation } from "@/core/api/graphql/composables"; -import { AddBulkItemsCartDocument, OperationNames } from "@/core/api/graphql/types"; -import { filterActiveQueryNames } from "@/core/api/graphql/utils"; +import { AddBulkItemsCartDocument } from "@/core/api/graphql/types"; import type { BulkCartType, InputNewBulkItemType, CartIdFragment } from "@/core/api/graphql/types"; import type { MaybeRef } from "vue"; export function useAddBulkItemsCartMutation(cart?: MaybeRef) { - const { client } = useApolloClient(); - return useMutation( - AddBulkItemsCartDocument, - useCartMutationVariables(cart, { - refetchQueries: () => filterActiveQueryNames(client, [OperationNames.Query.GetFullCart]), - }), - ); + return useMutation(AddBulkItemsCartDocument, useCartMutationVariables(cart, {})); } /** @deprecated Use {@link useAddBulkItemsCartMutation} instead. */ diff --git a/client-app/core/api/graphql/cart/mutations/addItemToCart/index.ts b/client-app/core/api/graphql/cart/mutations/addItemToCart/index.ts index 9028e2943b..95bebfab86 100644 --- a/client-app/core/api/graphql/cart/mutations/addItemToCart/index.ts +++ b/client-app/core/api/graphql/cart/mutations/addItemToCart/index.ts @@ -1,19 +1,11 @@ -import { useApolloClient } from "@vue/apollo-composable"; import { useCartMutationVariables } from "@/core/api/graphql/cart/composables"; import { useMutation } from "@/core/api/graphql/composables"; -import { AddItemDocument, OperationNames } from "@/core/api/graphql/types"; -import { filterActiveQueryNames } from "@/core/api/graphql/utils"; +import { AddItemDocument } from "@/core/api/graphql/types"; import type { CartType, CartIdFragment } from "@/core/api/graphql/types"; import type { MaybeRef } from "vue"; export function useAddItemToCartMutation(cart?: MaybeRef) { - const { client } = useApolloClient(); - return useMutation( - AddItemDocument, - useCartMutationVariables(cart, { - refetchQueries: () => filterActiveQueryNames(client, [OperationNames.Query.GetFullCart]), - }), - ); + return useMutation(AddItemDocument, useCartMutationVariables(cart)); } /** @deprecated Use {@link useAddItemToCartMutation} instead. */ diff --git a/client-app/core/api/graphql/cart/mutations/addItemsCart/index.ts b/client-app/core/api/graphql/cart/mutations/addItemsCart/index.ts index 56254f687e..4c79bf7119 100644 --- a/client-app/core/api/graphql/cart/mutations/addItemsCart/index.ts +++ b/client-app/core/api/graphql/cart/mutations/addItemsCart/index.ts @@ -1,19 +1,11 @@ -import { useApolloClient } from "@vue/apollo-composable"; import { useCartMutationVariables } from "@/core/api/graphql/cart/composables"; import { useMutation } from "@/core/api/graphql/composables"; -import { AddItemsCartDocument, OperationNames } from "@/core/api/graphql/types"; -import { filterActiveQueryNames } from "@/core/api/graphql/utils"; +import { AddItemsCartDocument } from "@/core/api/graphql/types"; import type { CartType, InputNewCartItemType, CartIdFragment } from "@/core/api/graphql/types"; import type { MaybeRef } from "vue"; export function useAddItemsCartMutation(cart?: MaybeRef) { - const { client } = useApolloClient(); - return useMutation( - AddItemsCartDocument, - useCartMutationVariables(cart, { - refetchQueries: () => filterActiveQueryNames(client, [OperationNames.Query.GetFullCart]), - }), - ); + return useMutation(AddItemsCartDocument, useCartMutationVariables(cart, {})); } /** @deprecated Use {@link useAddItemsCartMutation} instead. */ diff --git a/client-app/core/api/graphql/cart/mutations/changeShortCartItemQuantity/index.ts b/client-app/core/api/graphql/cart/mutations/changeShortCartItemQuantity/index.ts index ba652c5006..68055362e7 100644 --- a/client-app/core/api/graphql/cart/mutations/changeShortCartItemQuantity/index.ts +++ b/client-app/core/api/graphql/cart/mutations/changeShortCartItemQuantity/index.ts @@ -1,17 +1,9 @@ -import { useApolloClient } from "@vue/apollo-composable"; import { useCartMutationVariables } from "@/core/api/graphql/cart/composables"; import { useMutation } from "@/core/api/graphql/composables"; -import { ChangeShortCartItemQuantityDocument, OperationNames } from "@/core/api/graphql/types"; -import { filterActiveQueryNames } from "@/core/api/graphql/utils"; +import { ChangeShortCartItemQuantityDocument } from "@/core/api/graphql/types"; import type { CartIdFragment } from "@/core/api/graphql/types"; import type { MaybeRef } from "vue"; export function useChangeShortCartItemQuantityMutation(cart?: MaybeRef) { - const { client } = useApolloClient(); - return useMutation( - ChangeShortCartItemQuantityDocument, - useCartMutationVariables(cart, { - refetchQueries: () => filterActiveQueryNames(client, [OperationNames.Query.GetFullCart]), - }), - ); + return useMutation(ChangeShortCartItemQuantityDocument, useCartMutationVariables(cart, {})); } diff --git a/client-app/core/api/graphql/cart/queries/getShortCart/index.ts b/client-app/core/api/graphql/cart/queries/getShortCart/index.ts index 0a5cc3f9bc..7fe1ce427d 100644 --- a/client-app/core/api/graphql/cart/queries/getShortCart/index.ts +++ b/client-app/core/api/graphql/cart/queries/getShortCart/index.ts @@ -1,14 +1,10 @@ import { useQuery } from "@vue/apollo-composable"; -import { computed } from "vue"; -import { useRoute } from "vue-router"; import { useCartQueryVariables } from "@/core/api/graphql/cart/composables"; import { GetShortCartDocument } from "@/core/api/graphql/types"; export function useGetShortCartQuery() { - const route = useRoute(); - const isCartPage = computed(() => route.name === "Cart"); return useQuery(GetShortCartDocument, useCartQueryVariables(), { notifyOnNetworkStatusChange: true, - fetchPolicy: isCartPage.value ? "cache-only" : "cache-first", + fetchPolicy: "cache-first", }); } diff --git a/client-app/pages/cart.vue b/client-app/pages/cart.vue index 716f13e53f..5a7fb6026d 100644 --- a/client-app/pages/cart.vue +++ b/client-app/pages/cart.vue @@ -1,5 +1,5 @@