The Relay Store
provides an API for dispatching mutations to the server.
Methods
static commitUpdate(mutation: RelayMutation, callbacks: { onFailure?: (transaction: RelayMutationTransaction) => void; onSuccess?: (response: Object) => void; }): RelayMutationTransaction // Argument to `onFailure` callback type Transaction = { getError(): ?Error; }
The commitUpdate
method is analogous to dispatching an action in Flux. Relay processes
the mutation as follows:
getCollisionKey
implementation - it is sent to the server. If it would conflict, it is enqueued until conflicting mutations have completed.onSuccess
is called if the mutation succeeded.onFailure
is called if the mutation failed.var onSuccess = () => { console.log('Mutation successful!'); }; var onFailure = (transaction) => { var error = transaction.getError() || new Error('Mutation failed.'); console.error(error); }; var mutation = new MyMutation({...}); Relay.Store.commitUpdate(mutation, {onFailure, onSuccess});
static applyUpdate(mutation: RelayMutation, callbacks: { onFailure?: (transaction: RelayMutationTransaction) => void; onSuccess?: (response: Object) => void; }): RelayMutationTransaction
The applyUpdate
adds a mutation just like update
, but does not commit it. It returns a RelayMutationTransaction
that can be committed or rollbacked.
When the transaction is committed and the response is received from the server, one of the callbacks is invoked:
- onSuccess
is called if the mutation succeeded.
- onFailure
is called if the mutation failed.
var onSuccess = () => { console.log('Mutation successful!'); }; var onFailure = (transaction) => { var error = transaction.getError() || new Error('Mutation failed.'); console.error(error); }; var mutation = new MyMutation({...}); var transaction = Relay.Store.applyUpdate(mutation, {onFailure, onSuccess}); transaction.commit();