Skip to content

Commit

Permalink
feat: add shop loader and GraphQL query for shop information
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriassuncx committed Feb 5, 2025
1 parent d3b4324 commit 7a95122
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 8 deletions.
33 changes: 33 additions & 0 deletions shopify/loaders/shop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { AppContext } from "../mod.ts";
import { GetShopInfo } from "../utils/storefront/queries.ts";
import {
Shop,
ShopMetafieldsArgs,
} from "../utils/storefront/storefront.graphql.gen.ts";
import { Metafield } from "../utils/types.ts";

export interface Props {
/**
* @title Metafields
* @description search for metafields
*/
metafields?: Metafield[];
}

const loader = async (
props: Props,
_req: Request,
ctx: AppContext,
): Promise<Shop> => {
const { storefront } = ctx;
const { metafields = [] } = props;

const shop = await storefront.query<{ shop: Shop }, ShopMetafieldsArgs>({
variables: { identifiers: metafields },
...GetShopInfo,
}).then((data) => data.shop);

return shop;
};

export default loader;
6 changes: 4 additions & 2 deletions shopify/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import * as $$$1 from "./loaders/ProductList.ts";
import * as $$$2 from "./loaders/ProductListingPage.ts";
import * as $$$5 from "./loaders/proxy.ts";
import * as $$$3 from "./loaders/RelatedProducts.ts";
import * as $$$6 from "./loaders/user.ts";
import * as $$$6 from "./loaders/shop.ts";
import * as $$$7 from "./loaders/user.ts";

const manifest = {
"loaders": {
Expand All @@ -25,7 +26,8 @@ const manifest = {
"shopify/loaders/ProductListingPage.ts": $$$2,
"shopify/loaders/proxy.ts": $$$5,
"shopify/loaders/RelatedProducts.ts": $$$3,
"shopify/loaders/user.ts": $$$6,
"shopify/loaders/shop.ts": $$$6,
"shopify/loaders/user.ts": $$$7,
},
"handlers": {
"shopify/handlers/sitemap.ts": $$$$0,
Expand Down
66 changes: 60 additions & 6 deletions shopify/utils/storefront/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ const Customer = gql`

export const CreateCart = {
query: gql`mutation CreateCart {
payload: cartCreate {
cart { id }
}
}`,
payload: cartCreate {
cart { id }
}
}`,
};

export const GetCart = {
Expand All @@ -276,8 +276,8 @@ export const GetProduct = {
fragments: [Product, ProductVariant, Collection],
query:
gql`query GetProduct($handle: String, $identifiers: [HasMetafieldsIdentifier!]!) {
product(handle: $handle) { ...Product }
}`,
product(handle: $handle) { ...Product }
}`,
};

export const ListProducts = {
Expand Down Expand Up @@ -386,6 +386,60 @@ export const ProductRecommendations = {
}`,
};

export const GetShopInfo = {
query: gql`query GetShopInfo($identifiers: [HasMetafieldsIdentifier!]!) {
shop {
name
description
privacyPolicy {
title
body
}
refundPolicy {
title
body
}
shippingPolicy {
title
body
}
subscriptionPolicy {
title
body
}
termsOfService {
title
body
}
metafields(identifiers: $identifiers) {
description
key
namespace
type
value
reference {
... on MediaImage {
image {
url
}
}
}
references(first: 250) {
edges {
node {
... on MediaImage {
image {
url
}
}
}
}
}
}
}
}`,
};

export const FetchCustomerInfo = {
fragments: [Customer],
query: gql`query FetchCustomerInfo($customerAccessToken: String!) {
Expand Down

0 comments on commit 7a95122

Please sign in to comment.