facebook / facebook/relay

optimisticUpdater has invalid signature

Open
#4,590 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Hi folks. While trying to implement an `optimisticUpdater` for my app's mutations, I noticed the function has an invalid signature in Typescript (and possibly Flow as well).

Consider the following snippet:
```tsx
const [commitEditCategoryMutation, isCommitEditCategoryMutationInFlight] =
useMutation(graphql`
mutation TransactionDetailsV2ScreenEditCategoryMutation(
$input: TransactionsUpdateTransactionInput!
) {
transactionsUpdateTransaction(input: $input) {
...TransactionDetailsV2ScreenEditCategoryMutation_updatable
...TransactionDetailsV2HeaderFragment
...TransactionRowFragment
}
}
`);

// Later on
commitEditCategoryMutation({
variables: {
input,
},
optimisticUpdater(store, data) {
console.log("Optimistic updater data: ", data); // returns undefined, but TS type indicate otherwise
},
updater(store, data) {
console.log(`Data: ${data}`); // returns the expected value
},
})
```

Since `data` represents the server response, it makes sense for it to be undefined in `optimisticUpdater`. However, the types indicate otherwise.

I believe the issue is due to these lines:
* [Flow](https://github.com/facebook/relay/blob/1b588448804a37bed55e90373c3a78aaf17d14bf/packages/relay-runtime/mutations/commitMutation.js#L71-L72)
* [Typescript](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-relay/relay-hooks/useMutation.d.ts#L16-L18)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.