The Relay Store
provides an API for dispatching mutations to the server.
Methods
static commitUpdate(mutation, callbacks)
Initiate processing of a mutation. static applyUpdate(mutation, callbacks)
Adds a MutationTransaction to the queue without committing it. Note: Equivalent applyUpdate
and commitUpdate
methods are also provided on the this.props.relay
prop that is passed to components by Relay.Container
. These dispatch mutations in the context of the currently active Relay.Environment
.
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();
© 2013–present Facebook Inc.
Licensed under the BSD License.
https://facebook.github.io/relay/docs/api-reference-relay-store.html