graphqlapollooptimistic-ui

Graphql Apollo Optimistic UI pattern - handle actual result?


We are following the optimistic ui pattern (http://dev.apollodata.com/react/optimistic-ui.html) with the apollo graphql client. Is there a way to handle the actual result from the server? For example, if the server did error on the mutation, we would like to notify the user. Is there a place to get the real result of the mutation?


Solution

  • The mutation returns a Promise. So you can handle the result from the server using than and catch.

    If you are using the update functionality of the mutation definition you could use the catch to handle a server error. To get the error as object you could use errorResponse = JSON.parse(JSON.stringify(mutationError))