我在我的应用程序中使用了阿波罗突变。一切正常,直到我尝试将变量传递给此突变。我的代码:
const DELETE_WORD = gql`
mutation($eng_word: String!) {
deleteWord(eng_word: $engWord) {
eng_word
}
}
`;
const deleteWord = engWord => {
deleteWordHook({ variables: { engWord } }).then(closeModal());
refetch();
};
在调用deleteWord之后,我收到未提供任何有价值反馈的错误。
这是工作代码(没有传递变量):
const DELETE_WORD = gql`
mutation {
deleteWord(eng_word: "apple") {
eng_word
}
}
`;
const deleteWord = engWord => {
deleteWordHook().then(closeModal());
refetch();
};
答案 0 :(得分:0)
您将错误的参数传递给突变。您应该将eng_word
传递给deleteWordHook的变量。
试试这个:
const DELETE_WORD = gql`
mutation($eng_word: String!) {
deleteWord(eng_word: $engWord) {
eng_word
}
}
`;
const deleteWord = engWord => {
deleteWordHook({ variables: { eng_word: engWord } }).then(closeModal());
refetch();
};
答案 1 :(得分:0)
由于您在调用突变点时通过了 engWord ,因此, 您在声明突变时也应使用相同的名称。像下面那样更改您的代码应该可以
const DELETE_WORD = gql`
mutation($engWord: String!) {
deleteWord(eng_word: $engWord) {