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

refactor/shopify-functions-to-trpc #7

Merged
merged 3 commits into from
Nov 21, 2023
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
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}
],
"cSpell.words": [
"healthcheck",
"Quixer",
"shopify",
"superjson",
Expand Down
15 changes: 13 additions & 2 deletions apps/commerce/src/app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import env from '@/sdk/env';
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
import { type NextRequest } from 'next/server';
import { appRouter, createTRPCContext } from 'server';
import { appRouter, createTRPCContext, integrations } from 'server';

const handler = (req: NextRequest) =>
fetchRequestHandler({
endpoint: '/api/trpc',
req,
router: appRouter,
createContext: () => createTRPCContext({ req }),
createContext: () =>
createTRPCContext({
req,
integrations: {
shopify: {
client: new integrations.shopify.client(
env.SHOPIFY_STOREFRONT_ACCESS_TOKEN,
`${env.SHOPIFY_STORE_DOMAIN}`
)
}
}
}),
onError:
env.NODE_ENV === 'development'
? ({ path, error }) => {
Expand Down
19 changes: 0 additions & 19 deletions apps/commerce/src/app/client-component.tsx

This file was deleted.

16 changes: 5 additions & 11 deletions apps/commerce/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { api } from '@/sdk/lib/trpc/server';
import { Suspense } from 'react';
import { ClientComponent } from './client-component';
import { PPRComponent } from './ppr-component';
import Link from 'next/link';

export default async function HomePage() {
const hello = await api.hello.hello();

return (
<div className="flex min-h-screen flex-col items-center p-24">
<span>{hello.greeting} Server Component</span>
<ClientComponent />
<Suspense fallback={<div>Loading PPR Component...</div>}>
<PPRComponent />
</Suspense>
<span>Home</span>
<Link href="/product/camiseta-de-manga-longa" prefetch>
Produto Teste
</Link>
</div>
);
}
18 changes: 0 additions & 18 deletions apps/commerce/src/app/ppr-component.tsx

This file was deleted.

10 changes: 7 additions & 3 deletions apps/commerce/src/app/product/[handle]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HIDDEN_PRODUCT_TAG } from '@/sdk/lib/constants';
import { getProduct } from '@/sdk/lib/shopify';
import { api } from '@/sdk/lib/trpc/server';
import { Metadata } from 'next';
import { notFound } from 'next/navigation';

Expand All @@ -14,7 +14,9 @@ export async function generateMetadata({
}: {
params: { handle: string };
}): Promise<Metadata> {
const product = await getProduct(params.handle);
const product = await api.product.getProductByHandle({
handle: params.handle
});

if (!product) return notFound();

Expand Down Expand Up @@ -49,7 +51,9 @@ export async function generateMetadata({
}

export default async function ProductPage({ params }: Props) {
const product = await getProduct(params.handle);
const product = await api.product.getProductByHandle({
handle: params.handle
});

if (!product) return notFound();

Expand Down
105 changes: 0 additions & 105 deletions apps/commerce/src/sdk/lib/shopify/fragments/product.ts

This file was deleted.

82 changes: 0 additions & 82 deletions apps/commerce/src/sdk/lib/shopify/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/commerce/src/sdk/lib/shopify/queries/index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions apps/commerce/src/sdk/lib/shopify/reshapes/cart.ts

This file was deleted.

16 changes: 0 additions & 16 deletions apps/commerce/src/sdk/lib/shopify/reshapes/image.ts

This file was deleted.

37 changes: 0 additions & 37 deletions apps/commerce/src/sdk/lib/shopify/reshapes/product.ts

This file was deleted.

Loading
Loading