Skip to content

Commit

Permalink
refactor: change detail product fetching to server fetching function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ssoon-m committed Sep 13, 2024
1 parent 54d7d1b commit 1b0f67c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/web/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ type ProductOutput {
"""
isMyWishlist: Boolean
isPrivate: Boolean!
isProfitUrl: Boolean!
mallId: Int
"""
์‡ผํ•‘๋ชฐ ์ด๋ฆ„
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ProductQueries } from '@/entities/product';

const ProductDetailContainerServer = async ({ productId }: { productId: number }) => {
const queryClient = new QueryClient();
await queryClient.prefetchQuery(ProductQueries.product({ id: productId }));
await queryClient.prefetchQuery(ProductQueries.productServer({ id: productId }));
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<BasicLayout header={<ProductDetailPageHeader productId={productId} />}>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/products/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function generateMetadata({ params }: { params: { id: string } }):

const id = params.id;

const { product } = await ProductService.getProduct({ id: +id });
const { product } = await ProductService.getProductServer({ id: +id });
if (!product) return defaultMetadata;
const productGuides = await ProductService.getProductGuides({ productId: +product.id });

Expand Down
11 changes: 11 additions & 0 deletions apps/web/src/entities/product/product.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ export const ProductQueries = {
],
queryFn: () => ProductService.getProduct(variables),
}),
productServer: (variables: ProductQueryVariables) =>
queryOptions({
queryKey: [
...ProductQueries.all(),
'detail',
{
id: variables.id,
},
],
queryFn: () => ProductService.getProductServer(variables),
}),
products: (variables: QueryProductsQueryVariables) =>
queryOptions({
queryKey: [
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/shared/api/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ export type ProductOutput = {
/** ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ์œ„์‹œ๋ฆฌ์ŠคํŠธ ์—ฌ๋ถ€ */
isMyWishlist?: Maybe<Scalars['Boolean']['output']>;
isPrivate: Scalars['Boolean']['output'];
isProfitUrl: Scalars['Boolean']['output'];
mallId?: Maybe<Scalars['Int']['output']>;
/** ์‡ผํ•‘๋ชฐ ์ด๋ฆ„ */
mallName?: Maybe<Scalars['String']['output']>;
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/shared/api/product/product.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class ProductService {
return httpClient.execute(QueryProduct, variables).then((res) => res.data);
}

static async getProductServer(variables: ProductQueryVariables) {
return httpClient.server_execute(QueryProduct, variables).then((res) => res.data);
}

static async getProducts(variables: QueryProductsQueryVariables) {
return httpClient.execute(QueryProducts, variables).then((res) => res.data);
}
Expand Down

0 comments on commit 1b0f67c

Please sign in to comment.