I try to pass variables to my mutation in react project. It is working static code:
const EDIT_WORD = gql`
mutation {
editWord(
eng_word: "apple"
data: { eng_word: "apple1", ru_word: "яблоко1" }
) {
eng_word
}
}
...
const [editWordHook] = useMutation(EDIT_WORD);
...
editWordHook();
It is code with some mistake:
const EDIT_WORD = gql`
mutation($eng_word: String!, $data: wordInput!) {
editWord(
eng_word: $eng_word
data: { eng_word: $eng_word, ru_word: $ru_word }
) {
eng_word
}
}
`;
...
const [editWordHook] = useMutation(EDIT_WORD);
...
editWordHook({
variables: {
eng_word: editedWord,
data: {
eng_word: englishWordText,
ru_word: russianWordText,
},
},
});
Instead of [$data: wordInput!] I tried
$data: { $eng_word: String!, $ru_word: String! }
But is didn't help... Error log didn't provide anything valuable:
// value or the constructed error will be meaningless.
> 46 | constructor({
| ^ 47 | graphQLErrors,
48 | networkError,
49 | errorMessage,
Already spent 10 hours and can't find mistake...