Преглед изворни кода

添加搜索产品graphql请求语句,结果类型和参数类型

zgl пре 4 дана
родитељ
комит
eab1a41261

+ 36 - 0
src/components/catalog/type.ts

@@ -122,6 +122,9 @@ export interface ProductNode {
   };
   };
   price?: string | number | { value?: number; currencyCode?: string } | null;
   price?: string | number | { value?: number; currencyCode?: string } | null;
   minimumPrice?: string | number;
   minimumPrice?: string | number;
+  formattedPrice?: string;
+  formattedSpecialPrice?: string | null;
+  formattedMinimumPrice?: string;
   productOptions?: string | null;
   productOptions?: string | null;
   flexibleVariants?: Array<ProductFlexibleVariant>;
   flexibleVariants?: Array<ProductFlexibleVariant>;
   priceHtml?: {
   priceHtml?: {
@@ -157,6 +160,39 @@ export interface ProductsResponse {
   };
   };
 }
 }
 
 
+export interface SearchProductsVariables {
+    query: string;
+    suggest?: boolean;
+    filter?: string;
+    sortKey?: string;
+    reverse?: boolean;
+    first?: number;
+    last?: number;
+    after?: string;
+    before?: string;
+    channel?: string;
+    locale?: string;
+}
+export interface SearchProductsResponse {
+  search: {
+    edges: Array<{ node: ProductNode }>;
+    pageInfo: {
+      endCursor: string;
+      startCursor: string;
+      hasNextPage: boolean;
+      hasPreviousPage: boolean;
+    };
+    totalCount: number;
+
+    searchMetadata: {
+      originalQuery: string;
+      effectiveQuery: string;
+      resultMessage: string;
+      searchInsteadMessage: string;
+    }
+  };
+}
+
 export interface ProductSectionNode {
 export interface ProductSectionNode {
   id: string;
   id: string;
   sku: string;
   sku: string;

+ 3 - 0
src/graphql/catalog/fragments/ProductCore.ts

@@ -7,6 +7,9 @@ export const PRODUCT_CORE_FRAGMENT = gql`
     type
     type
     name
     name
     price
     price
+    formattedPrice
+    formattedSpecialPrice
+    formattedMinimumPrice
     urlKey
     urlKey
     baseImageUrl
     baseImageUrl
     minimumPrice
     minimumPrice

+ 54 - 0
src/graphql/catalog/queries/SearchProducts.ts

@@ -0,0 +1,54 @@
+import { gql,TypedDocumentNode } from "@apollo/client";
+import { PRODUCT_CORE_FRAGMENT } from "../fragments";
+import { SearchProductsResponse } from "@/components/catalog/type";
+
+export const SEARCH_PRODUCTS: TypedDocumentNode<SearchProductsResponse> = gql`
+  ${PRODUCT_CORE_FRAGMENT}
+
+  query SearchProducts(
+    $query: String!
+    $suggest: Boolean
+    $sortKey: String
+    $reverse: Boolean
+    $first: Int
+    $last: Int
+    $after: String
+    $before: String
+    $channel: String
+    $locale: String
+    $filter: String
+  ) {
+    search(
+      query: $query
+      suggest: $suggest
+      filter: $filter
+      sortKey: $sortKey
+      reverse: $reverse
+      first: $first
+      last: $last
+      after: $after
+      before: $before
+      channel: $channel
+      locale: $locale
+      
+    ) {
+
+        totalCount
+        edges {
+            node { ...ProductCore }
+        }
+        pageInfo {
+            hasNextPage
+            hasPreviousPage
+            startCursor
+            endCursor
+        }
+        searchMetadata {
+            originalQuery
+            effectiveQuery
+            resultMessage
+            searchInsteadMessage
+        }
+    }
+  }
+`;

+ 5 - 5
src/utils/bagisto/index.ts

@@ -19,7 +19,7 @@ import {
   CUSTOMER_REGISTRATION,
   CUSTOMER_REGISTRATION,
   FORGET_PASSWORD,
   FORGET_PASSWORD,
 } from "@/graphql/customer/mutations";
 } from "@/graphql/customer/mutations";
-import { DocumentNode } from "graphql";
+import { print, DocumentNode } from "graphql";
 import { 
 import { 
   GRAPHQL_URL, 
   GRAPHQL_URL, 
   REST_API_URL,
   REST_API_URL,
@@ -172,12 +172,12 @@ export async function serverGraphqlFetch<
   TData,
   TData,
   TVariables = Record<string, never>
   TVariables = Record<string, never>
 >({
 >({
-  cache = "force-cache",
+  cache = "no-store",
   headers,
   headers,
   query,
   query,
   tags,
   tags,
   variables,
   variables,
-  revalidate = 60,
+  revalidate = 0,
   operationName = ''
   operationName = ''
 }: {
 }: {
   cache?: RequestCache;
   cache?: RequestCache;
@@ -189,7 +189,7 @@ export async function serverGraphqlFetch<
   operationName?: string;
   operationName?: string;
 }): Promise<FetchGraphqlResult<TData>> {
 }): Promise<FetchGraphqlResult<TData>> {
   try {
   try {
-    const queryString = typeof query === "string" ? query : (query.loc?.source?.body ?? "");
+    const queryString = typeof query === "string" ? query : print(query);
 
 
     let accessToken: string | undefined = undefined;
     let accessToken: string | undefined = undefined;
     let guestToken: string | undefined = undefined;
     let guestToken: string | undefined = undefined;
@@ -284,7 +284,7 @@ export async function bagistoFetch<T>({
 }): Promise<{ status: number; body: T } | never> {
 }): Promise<{ status: number; body: T } | never> {
   try {
   try {
     const queryString =
     const queryString =
-      typeof query === "string" ? query : (query.loc?.source?.body ?? "");
+      typeof query === "string" ? query : print(query);
 
 
     let bagistoCartId = "";
     let bagistoCartId = "";
     let accessToken: string | undefined = undefined;
     let accessToken: string | undefined = undefined;