我正在使用诸如此类的graphql突变,.then和.catch可以完美地工作:
let submitForm = (
email: string,
firstName: string
) => {
setIsSubmitted(true);
if (email && (firstName)) {
const input: UpdateUserInput = {};
if (firstName) {
input.firstName = firstName;
}
updateUser({
variables: {
email: email,
input: input,
},
})
.then(({ data }: ExecutionResult<UpdateUserResponse>) => {
if (data !== null && data !== undefined) {
setIsUpdated(true);
}
})
.catch((error: { message: string }) => {
console.log('Error msg:' + error.message);
});
}
};
现在我在这里为graphql查询做类似的事情:
let ShowUsers = () => {
const where: WhereInput = {};
if (criteria === '2') {
if (searchItem) {
where.firstName_contains = searchItem;
loadUsers({
variables: {
where: where
},
})
.then(({ data }: any) => {
if (data !== null && data !== undefined) {
}
})
}
}
}
但是我不断收到错误消息,说明'void'类型的属性'then'不存在。ts(2339)''
这取决于loadUsers
中到底发生了什么,但是您可能忘记了那里的return语句。
如果您更改loadUsers
以返回对用户的承诺,则您的代码应该可以正常工作。