Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
I'm trying to run custom GraphQL mutation on the storefront and update the checkout email
I'm using js-buy-sdk and according to the documentation it should be possible to run any custom GraphQL query or mutation. Using an updateEmail method source I recreated it in my codebase:
const emailMutation = `mutation checkoutEmailUpdateV2($checkoutId: ID!, $email: String!) {
checkoutEmailUpdateV2(checkoutId: $checkoutId, email: $email) {
userErrors {
...UserErrorFragment
}
checkoutUserErrors {
...CheckoutUserErrorFragment
}
checkout {
...CheckoutFragment
}
}
}`
const vars = {
checkoutId: cartInstance.id,
note: 'test@test.com'
}
this.client.graphQLClient.send(emailMutation, vars).then(({model, data}) => {
console.log(model);
});
When I run it I get this error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')
at Client.send
Do I need to parse the emailMutation as GraphQL somehow? Any ideas?
Hey there,
I am very interested in this approach, did you end up to make it work ? :3
Well, for the ones that wonder, I have found two solution to this problem, with the use of shopify-buy sdk: