0
votes

I have a relay mutation that posts some data to my server. My app shouldn't wait for the response before continuing.

I know I can execute arbitrary queries with the following:

const query = Relay.createQuery(Relay.QL`
  query {
    viewer {
      searchInterests(prefix: $prefix, first: 10) {
        edges {
          node {
            id
            name
          }
        }
      }
    },
  }
`, {prefix: input});

Relay.Store.primeCache({query}, readyState => {
  if (readyState.done) {
    // When all data is ready, read the data from the cache:
    const data = Relay.Store.readQuery(query)[0];

    ...
  }

How can I fire off mutations asynchronously without my app waiting for the response?

1
Actually it seems I just need to define an optimistic response according to the docs: facebook.github.io/relay/docs/…jbrown

1 Answers

0
votes

When designing a fat query, consider all of the data that might change as a result of the mutation – not just the data currently in use by your application. We don't need to worry about overfetching; this query is never executed without first intersecting it with a ‘tracked query’ of the data our application actually needs. If we omit fields in the fat query, we might observe data inconsistencies in the future when we add views with new data dependencies, or add new data dependencies to existing views.