I have this login case
let result;
try {
result = await relayCommitUpdate(this.context.relay, LoginMutation, {
email, password
});
} catch (trans) {
let error = trans.getError();
this.props.setLoginError(error);
}
When login succeeds, everything is okay. However, when GraphQL server responds with an error (i.e. user not found), this error shows.
Error: RelayMutationQueue: `0` is not a valid pending transaction ID.
btw, the response body is
{
"data": {
"login": null
},
"errors": [
{
"message": "user not found",
"locations": [
{
"line": 2,
"column": 3
}
]
}
]
}
Why is this happening?
Interesting, it looks like it's failing to add to the pendingTransactions map, or deleted somehow. When it tries to get the error, the transaction does not exist anymore.
whats relayCommitUpdate here @aihornmac ?
it's a helper function to make commitUpdate into promise style, source code appended
export default function CommitUpdate (relay, Mutation, variables) {
return new Promise((resolve, reject) => {
relay.commitUpdate(
new Mutation(variables), {
onSuccess: resolve,
onFailure: reject,
}
);
});
}
So I think what's happening here is that the transaction is rollbacked and removed from pending transactions.
When you try to getError() on the transaction, it looks for it in the pending ones and 馃挜
Is it a bug? How should I fix this?
I'm not sure if it's a bug, but the error message here definitly doesnt help.
I think it has to do with your promise. I believe handleCommitFailure expected onFailure to run inline, so the transaction is rollbacked before your own onFailure is ran.
Can you run it inline (without the promise) ? it should work as expected because you can access the transaction before it's rollbacked.
You are totally right! When I try getError before rejection, it doesn't throw anymore! Thank you for help!
np!, Still pretty surprising behaviour though, wonder what you think of this issue @josephsavona
Yet I am surprised that getError has to be run before next loop.
Hmm - I agree that getError would ideally work even after the transaction was rolled back. Anyone interested in submitting a PR to change?
I'll try to come up with something this week @josephsavona
Most helpful comment
I'll try to come up with something this week @josephsavona