Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Shopify] - Feat: add shop loader and GraphQL query for shop information #1001

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions shopify/loaders/shop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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[];
}

export const defaultVisibility = "private";

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
Loading