feat: Add stories

This commit is contained in:
Sol Irvine
2023-08-20 13:25:41 +09:00
parent ab8923080b
commit b994e62c21
16 changed files with 380 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ import {
editCartItemsMutation,
removeFromCartMutation
} from './mutations/cart';
import { getBlogQuery } from './queries/blog';
import { getCartQuery } from './queries/cart';
import {
getCollectionProductsQuery,
@@ -23,6 +24,7 @@ import {
getProductsQuery
} from './queries/product';
import {
Blog,
Cart,
Collection,
Connection,
@@ -31,6 +33,8 @@ import {
Page,
Product,
ShopifyAddToCartOperation,
ShopifyBlog,
ShopifyBlogOperation,
ShopifyCart,
ShopifyCartOperation,
ShopifyCollection,
@@ -167,6 +171,19 @@ const reshapeImages = (images: Connection<Image>, productTitle: string) => {
});
};
const reshapeBlog = (blog: ShopifyBlog) => {
if (!blog) {
return undefined;
}
const { articles, ...rest } = blog;
return {
...rest,
articles: removeEdgesAndNodes(articles)
};
};
const reshapeProduct = (product: ShopifyProduct, filterHiddenProducts: boolean = true) => {
if (!product || (filterHiddenProducts && product.tags.includes(HIDDEN_PRODUCT_TAG))) {
return undefined;
@@ -397,6 +414,25 @@ export async function getPages({
return removeEdgesAndNodes(res.body.data.pages);
}
export async function getBlog({
handle,
articles,
language,
country
}: {
handle: string;
articles?: number;
language?: string;
country?: string;
}): Promise<Blog | undefined> {
const res = await shopifyFetch<ShopifyBlogOperation>({
query: getBlogQuery,
variables: { handle, articles, language, country }
});
return reshapeBlog(res.body.data.blogByHandle);
}
export async function getProduct({
handle,
language,