Чтобы передать переменные в мутацию, можно сделать что-то вроде:
const url = 'https://xxxx.myshopify.com/api/graphql';
const query = `
mutation customerCreate($input: CustomerCreateInput!) {
customerCreate(input: $input) {
userErrors {
field
message
}
customer {
id
}
}
}
`;
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: query,
variables: {
input: {
email: "test@test.com",
password: "pass"
}
},
}),
})
.then(res => res.json())
.then(res => console.log(res.data));
.catch(err => {
console.log('-- gql err --')
console.error(err);
})
И просто убедитесь, что variables
объект внутри JSON.stringify
должен соответствовать типу CustomerCreateInput
.