Template
Replace @shopify/hydrogen with direct Storefront API queries
Vercel's 'Hydrogen (v1)' preset matches any project depending on
@shopify/hydrogen and runs its v1 builder, which fails looking for
dist/worker. We only used the preview package as a Storefront API client,
so talk to the API directly instead:
- services/shopify/client.ts: plain fetch to /api/{version}/graphql.json
with the public token header, @inContext country/language defaults, and
the same graphql() / unwrapStorefrontResult API as before
- graphql/gql.ts: small helper that joins a document with its fragments
(de-duplicated); the queries themselves are unchanged
- Explicit response types at each call site in place of the generated
gql.tada types; local ProductFilter input type
- Drop @shopify/hydrogen, graphql, the TS plugin and 'hydrogen gql check'
- Copy no longer mentions Hydrogen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d33a6894f3
commit
6fcfe59d0d
@@ -80,6 +80,15 @@ export interface AuthResult {
|
||||
errors: CustomerUserError[];
|
||||
}
|
||||
|
||||
// Payload shapes the customer mutations select. Shopify returns a null payload
|
||||
// when a mutation could not run at all.
|
||||
interface UserErrorsPayload {
|
||||
customerUserErrors: CustomerUserError[] | null;
|
||||
}
|
||||
type TokenPayload = UserErrorsPayload & {
|
||||
customerAccessToken: AccessToken | null;
|
||||
};
|
||||
|
||||
const firstMessage = (errors: CustomerUserError[]) =>
|
||||
errors[0]?.message ?? 'Something went wrong. Please try again.';
|
||||
|
||||
@@ -100,9 +109,10 @@ export async function createCustomer(input: {
|
||||
acceptsMarketing?: boolean;
|
||||
}): Promise<{ errors: CustomerUserError[] }> {
|
||||
const data = unwrapStorefrontResult(
|
||||
await storefront.graphql(CUSTOMER_CREATE_MUTATION, {
|
||||
variables: { input },
|
||||
}),
|
||||
await storefront.graphql<{ customerCreate: UserErrorsPayload | null }>(
|
||||
CUSTOMER_CREATE_MUTATION,
|
||||
{ variables: { input } }
|
||||
),
|
||||
'CustomerCreate'
|
||||
);
|
||||
|
||||
@@ -117,9 +127,10 @@ export async function login(
|
||||
password: string
|
||||
): Promise<AuthResult> {
|
||||
const data = unwrapStorefrontResult(
|
||||
await storefront.graphql(CUSTOMER_ACCESS_TOKEN_CREATE_MUTATION, {
|
||||
variables: { input: { email, password } },
|
||||
}),
|
||||
await storefront.graphql<{ customerAccessTokenCreate: TokenPayload | null }>(
|
||||
CUSTOMER_ACCESS_TOKEN_CREATE_MUTATION,
|
||||
{ variables: { input: { email, password } } }
|
||||
),
|
||||
'CustomerAccessTokenCreate'
|
||||
);
|
||||
|
||||
@@ -161,9 +172,10 @@ export async function resetPassword(
|
||||
password: string
|
||||
): Promise<AuthResult> {
|
||||
const data = unwrapStorefrontResult(
|
||||
await storefront.graphql(CUSTOMER_RESET_MUTATION, {
|
||||
variables: { id, input: { resetToken, password } },
|
||||
}),
|
||||
await storefront.graphql<{ customerReset: TokenPayload | null }>(
|
||||
CUSTOMER_RESET_MUTATION,
|
||||
{ variables: { id, input: { resetToken, password } } }
|
||||
),
|
||||
'CustomerReset'
|
||||
);
|
||||
|
||||
@@ -182,9 +194,10 @@ export async function activateAccount(
|
||||
password: string
|
||||
): Promise<AuthResult> {
|
||||
const data = unwrapStorefrontResult(
|
||||
await storefront.graphql(CUSTOMER_ACTIVATE_MUTATION, {
|
||||
variables: { id, input: { activationToken, password } },
|
||||
}),
|
||||
await storefront.graphql<{ customerActivate: TokenPayload | null }>(
|
||||
CUSTOMER_ACTIVATE_MUTATION,
|
||||
{ variables: { id, input: { activationToken, password } } }
|
||||
),
|
||||
'CustomerActivate'
|
||||
);
|
||||
|
||||
@@ -203,7 +216,7 @@ export async function getCustomer(
|
||||
): Promise<Customer | null> {
|
||||
try {
|
||||
const data = unwrapStorefrontResult(
|
||||
await storefront.graphql(CUSTOMER_QUERY, {
|
||||
await storefront.graphql<{ customer: Customer | null }>(CUSTOMER_QUERY, {
|
||||
variables: { customerAccessToken: accessToken, orderCount },
|
||||
}),
|
||||
'GetCustomer'
|
||||
@@ -227,7 +240,9 @@ export async function updateCustomer(
|
||||
}
|
||||
): Promise<{ customer: Customer | null; errors: CustomerUserError[] }> {
|
||||
const data = unwrapStorefrontResult(
|
||||
await storefront.graphql(CUSTOMER_UPDATE_MUTATION, {
|
||||
await storefront.graphql<{
|
||||
customerUpdate: (UserErrorsPayload & { customer: Customer | null }) | null;
|
||||
}>(CUSTOMER_UPDATE_MUTATION, {
|
||||
variables: { customerAccessToken: accessToken, customer },
|
||||
}),
|
||||
'CustomerUpdate'
|
||||
|
||||
Reference in New Issue
Block a user