Querying by product variant using storefront api does not work. Please Fix.
During post purchase checkout, I need to retrieve a product variant to offer the user, then pass the variant ID to my sign-changeset api enpoint if the user accepts my post purchase offer. How is this doable if I am unable to query by product variant?
Example:
import { createStorefrontApiClient } from '@shopify/storefront-api-client';
const client = createStorefrontApiClient({
storeDomain: myDomain,
apiVersion: '2024-01',
publicAccessToken: myToken
});
export function App() {
useEffect(() => {
const vId = myVariantId;
const variantQuery = `
query getVariant($id: ID!) {
productVariant(id: $id) {
id
title
image {
url
}
}
}
`;
try {
const result = await client.request(variantQuery, {
variables: {
id: vId
}
});
if (!result || result.errors) {
(result?.errors && console.error(result.errors))
throw new Error(`Error getting variants: ${vId}`);
}
console.log('variant', result);
}
catch (e) {
console.error(e);
return null;
}
}
}, [])