Skip to content

Commit

Permalink
refactor: move graphql-generated types to shopify strategy directory
Browse files Browse the repository at this point in the history
  • Loading branch information
bmstefanski committed Feb 16, 2024
1 parent e3c5dea commit c2c0229
Show file tree
Hide file tree
Showing 11 changed files with 544 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .graphqlrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export default {
apiType: ApiType.Storefront,
apiVersion: "2024-01",
documents: ["./packages/core/**/*.storefront.{js,ts,jsx,tsx}", "./packages/core/**/fragments/*.{js,ts,jsx,tsx}"],
outputDir: "./types",
outputDir: "./packages/core/platform/shopify/types",
}),
admin: shopifyApiProject({
apiType: ApiType.Admin,
apiVersion: "2024-01",
documents: ["./packages/core/**/*.admin.{js,ts,jsx,tsx}"],
outputDir: "./types/admin",
outputDir: "./packages/core/platform/shopify/types/admin",
}),
},
}
5 changes: 2 additions & 3 deletions apps/web/app/api/sync/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { FailedAttemptError } from "p-retry"
import { Root } from "shopify-webhooks"
import { createHmac } from "crypto"

import { SingleProductQuery } from "../../../../../types/storefront.generated"

export async function POST(req: Request) {
const hmac = req.headers.get("X-Shopify-Hmac-Sha256")

Expand Down Expand Up @@ -45,7 +43,8 @@ export async function POST(req: Request) {
return Response.json({ status: "ok" })
}

function normalizeProduct(product: SingleProductQuery["product"] | undefined | null) {
// TODO: provide agnostic type
function normalizeProduct(product: any | undefined | null) {
if (!product) return product

return {
Expand Down
1 change: 1 addition & 0 deletions apps/web/views/Search/SearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function SearchView({ searchParams }: { searchParams: Record<string, stri
</DropdownMenu>
</div>
<NextInstantSearch
meilisearchOptions={{}}
searchParams={{ ...parsedSearchParams, q: parsedSearchParams.q || " " }}
options={{ revalidate: 60 }}
indexName="products"
Expand Down
6 changes: 3 additions & 3 deletions packages/core/platform/shopify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { getMenuQuery } from "./queries/menu.storefront"
import { getLatestProductFeedQuery } from "./queries/product-feed.admin"
import { getProductQuery, getProductsByHandleQuery } from "./queries/product.storefront"

import type { LatestProductFeedsQuery, ProductFeedCreateMutation, ProductFullSyncMutation, WebhookSubscriptionCreateMutation } from "../../../../types/admin/admin.generated"
import type { WebhookSubscriptionTopic } from "../../../../types/admin/admin.types"
import type { MenuQuery, ProductsByHandleQuery, SingleProductQuery } from "../../../../types/storefront.generated"
import type { LatestProductFeedsQuery, ProductFeedCreateMutation, ProductFullSyncMutation, WebhookSubscriptionCreateMutation } from "./types/admin/admin.generated"
import type { WebhookSubscriptionTopic } from "./types/admin/admin.types"
import type { MenuQuery, ProductsByHandleQuery, SingleProductQuery } from "./types/storefront.generated"

interface CreateShopifyClientProps {
storeDomain: string
Expand Down

Large diffs are not rendered by default.

File renamed without changes.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ export type SingleCartFragment = (
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) | (
Pick<StorefrontTypes.ComponentizableCartLine, 'id' | 'quantity'>
& { cost: { totalAmount: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, merchandise: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, product: (
Pick<StorefrontTypes.Product, 'id' | 'handle' | 'title' | 'description' | 'descriptionHtml' | 'tags' | 'updatedAt'>
& { options: Array<Pick<StorefrontTypes.ProductOption, 'id' | 'name' | 'values'>>, priceRange: { maxVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'>, minVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, variants: { edges: Array<{ node: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title' | 'availableForSale'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, price: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) }> } }
);

Expand Down Expand Up @@ -62,6 +74,18 @@ export type CreateCartLineMutation = { cartLinesAdd?: StorefrontTypes.Maybe<{ ca
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) | (
Pick<StorefrontTypes.ComponentizableCartLine, 'id' | 'quantity'>
& { cost: { totalAmount: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, merchandise: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, product: (
Pick<StorefrontTypes.Product, 'id' | 'handle' | 'title' | 'description' | 'descriptionHtml' | 'tags' | 'updatedAt'>
& { options: Array<Pick<StorefrontTypes.ProductOption, 'id' | 'name' | 'values'>>, priceRange: { maxVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'>, minVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, variants: { edges: Array<{ node: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title' | 'availableForSale'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, price: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) }> } }
)> }> };

Expand All @@ -84,6 +108,18 @@ export type CreateCartMutation = { cartCreate?: StorefrontTypes.Maybe<{ cart?: S
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) | (
Pick<StorefrontTypes.ComponentizableCartLine, 'id' | 'quantity'>
& { cost: { totalAmount: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, merchandise: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, product: (
Pick<StorefrontTypes.Product, 'id' | 'handle' | 'title' | 'description' | 'descriptionHtml' | 'tags' | 'updatedAt'>
& { options: Array<Pick<StorefrontTypes.ProductOption, 'id' | 'name' | 'values'>>, priceRange: { maxVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'>, minVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, variants: { edges: Array<{ node: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title' | 'availableForSale'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, price: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) }> } }
)> }> };

Expand All @@ -107,6 +143,18 @@ export type EditCartLineMutation = { cartLinesUpdate?: StorefrontTypes.Maybe<{ c
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) | (
Pick<StorefrontTypes.ComponentizableCartLine, 'id' | 'quantity'>
& { cost: { totalAmount: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, merchandise: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, product: (
Pick<StorefrontTypes.Product, 'id' | 'handle' | 'title' | 'description' | 'descriptionHtml' | 'tags' | 'updatedAt'>
& { options: Array<Pick<StorefrontTypes.ProductOption, 'id' | 'name' | 'values'>>, priceRange: { maxVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'>, minVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, variants: { edges: Array<{ node: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title' | 'availableForSale'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, price: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) }> } }
)> }> };

Expand All @@ -130,6 +178,18 @@ export type RemoveCartLineMutation = { cartLinesRemove?: StorefrontTypes.Maybe<{
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) | (
Pick<StorefrontTypes.ComponentizableCartLine, 'id' | 'quantity'>
& { cost: { totalAmount: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, merchandise: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, product: (
Pick<StorefrontTypes.Product, 'id' | 'handle' | 'title' | 'description' | 'descriptionHtml' | 'tags' | 'updatedAt'>
& { options: Array<Pick<StorefrontTypes.ProductOption, 'id' | 'name' | 'values'>>, priceRange: { maxVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'>, minVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, variants: { edges: Array<{ node: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title' | 'availableForSale'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, price: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) }> } }
)> }> };

Expand All @@ -152,6 +212,18 @@ export type SingleCartQuery = { cart?: StorefrontTypes.Maybe<(
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) | (
Pick<StorefrontTypes.ComponentizableCartLine, 'id' | 'quantity'>
& { cost: { totalAmount: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, merchandise: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, product: (
Pick<StorefrontTypes.Product, 'id' | 'handle' | 'title' | 'description' | 'descriptionHtml' | 'tags' | 'updatedAt'>
& { options: Array<Pick<StorefrontTypes.ProductOption, 'id' | 'name' | 'values'>>, priceRange: { maxVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'>, minVariantPrice: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }, variants: { edges: Array<{ node: (
Pick<StorefrontTypes.ProductVariant, 'id' | 'title' | 'availableForSale'>
& { selectedOptions: Array<Pick<StorefrontTypes.SelectedOption, 'name' | 'value'>>, price: Pick<StorefrontTypes.MoneyV2, 'amount' | 'currencyCode'> }
) }> }, featuredImage?: StorefrontTypes.Maybe<Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'>>, images: { edges: Array<{ node: Pick<StorefrontTypes.Image, 'url' | 'altText' | 'width' | 'height'> }> }, seo: Pick<StorefrontTypes.Seo, 'description' | 'title'> }
) }
) }
) }> } }
)> };

Expand Down
Loading

0 comments on commit c2c0229

Please sign in to comment.