Update Mutation API
@@ -22,7 +22,7 @@ commitMutation(
onCompleted?: ?(response: ?Object) => void,
onError?: ?(error: Error) => void,
optimisticResponse?: ?() => Object,
- optimisticUpdater?: ?(store: RecordSourceProxy) => void,
+ optimisticUpdater?: ?(store: RecordSourceSelectorProxy) => void,
updater?: ?(store: RecordSourceSelectorProxy) => void,
},
);
@@ -34,7 +34,9 @@ Now let's take a closer look at the `config`:
* `variables`: an object that contains the variables needed for the mutation.
* `onCompleted`: a callback function executed with the 'raw' response from the server after the in-memory Relay store is updated with the `updater`.
* `onError`: a callback function executed when Relay encounters an error.
-* `optimisticResponse`: a function that provides an object conforming to the mutation's response type definition. If an `optimisticUpdater` is not provided, Relay will use this to optimistically update the store.
+* `optimisticResponse`: a function that provides an object conforming to the mutation's response type definition. If provided, the optimistic response will be normalized to the proxy store before `optimisticUpdater` is executed. We suggest you provide an `optimisticResponse` for two benefits:
+ * Like `updater`, there is no need to provide `optimisticUpdater` for simple mutations (field change).
+ * For more complicated mutations, `optimisticUpdater` and `updater` can be the same function.
* `optimisticUpdater`: a function that takes in a proxy of the in-memory Relay store. In this function, the client defines 'how to' update the store through the proxy in an imperative way.
* `updater`: a function that updates the in-memory Relay store based on the **real** server response. When the server response comes back, Relay first reverts any changes introduced by `optimisticUpdater` or `optimisticResponse` and then applies the `updater` to the store.
