facebook / facebook/relay

optimisticUpdater does not work

Open
#2,345 15 comments 1 reaction 0 assignees View on GitHub
wontfix
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

So, I have this code.

```js
// @flow
import { graphql, commitMutation } from 'react-relay';
import type { Commit } from '../components/Mutation';
import type {
DeleteWebMutationVariables,
DeleteWebMutationResponse,
} from './__generated__/DeleteWebMutation.graphql';
import { ConnectionHandler } from 'relay-runtime';
import ensureConnection from './ensureConnection';

const mutation = graphql`
mutation DeleteWebMutation($input: DeleteWebInput!) {
deleteWeb(input: $input) {
id
}
}
`;

const sharedUpdater = (store, id) => {
const clientRoot = store.get('client:root');
const connection = ConnectionHandler.getConnection(clientRoot, 'Webs_webs');
ensureConnection(connection);
ConnectionHandler.deleteNode(connection, id);
};

const commit: Commit = (
environment,
variables,
onCompleted,
onError,
) =>
commitMutation(environment, {
mutation,
variables,
onCompleted,
onError,
updater: store => {
const payload = store.getRootField('deleteWeb');
const id = payload.getValue('id');
sharedUpdater(store, id);
},
// This breaks everything.
optimisticUpdater: store => {
sharedUpdater(store, variables.input.id);
},
});

export default { commit };
```

As optimisticUpdater does not work. I don't know why. Probably because of clientMutationId, maybe.

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.