我有一个React Native应用。
graphql中将变量传递给 customerCreate 的正确语法是什么?
const url = 'https://xxxx.myshopify.com/api/graphql';
const query = `
var variable = {
"input": {
"email": "test@test.com",
"password": "pass"
}
}
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 }),
})
.then(res => res.json())
.then(res => console.log(res.data));
.catch(err => {
console.log('-- gql err --')
console.error(err);
})
答案 0 :(得分:0)
将变量传递给突变的一种方法可以是:
newmap.entrySet().stream().filter(entry->entry.getKey().equals(student::getId)).collect(..collect here to list..);
只需确保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
匹配。