relay icon indicating copy to clipboard operation
relay copied to clipboard

optimisticUpdater has invalid signature

Open MarceloPrado opened this issue 5 months ago • 0 comments

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:

const [commitEditCategoryMutation, isCommitEditCategoryMutationInFlight] =
    useMutation<TransactionDetailsV2ScreenEditCategoryMutation>(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:

MarceloPrado avatar Jan 19 '24 12:01 MarceloPrado