getProductSwatchAndReview.ts 749 B

1234567891011121314151617181920212223242526
  1. import { SingleProductResponse } from "@/components/catalog/type";
  2. import { GET_PRODUCT_SWATCH_REVIEW } from "@/graphql";
  3. import { cachedProductRequest } from "@/utils/hooks/useCache";
  4. export async function getProductWithSwatchAndReview(urlKey: string) {
  5. try {
  6. const {data:dataById} = await cachedProductRequest<SingleProductResponse>(
  7. // urlKey,
  8. GET_PRODUCT_SWATCH_REVIEW,
  9. { urlKey: urlKey }
  10. );
  11. return dataById?.product || null;
  12. } catch (error) {
  13. if (error instanceof Error) {
  14. console.error("Error fetching product:", {
  15. message: error.message,
  16. urlKey,
  17. graphQLErrors: (error as unknown as Record<string, unknown>)
  18. .graphQLErrors,
  19. });
  20. }
  21. return null;
  22. }
  23. }