0

I'm trying to setup an optimisticResponse with a date column using react-apollo. My code is not properly returning the optimistic response data and rerendering my component accordingly. I'm assuming it's because I don't have the exact date that's being returned from my database.

Example object from mutation:

optimisticResponse: {
  postMessage: {
     id: -1,
     message,
     createdAt: moment().toISOString(),
     __typename: "Message",
  }
}

I'm using a pg database and autogenerating dates when my row is created ie.: ("2019-03-23T21:33:54.079Z"). I couldn't find any related issues and I'm at a loss for how to get around this.

Grant
  • 121
  • 5
  • 1
    Please clarify what you mean by "not properly returning the optimistic response data". Are you not seeing an optimistic response at all, or is it just returning different data than what comes back from the server (i.e. the issue is the timestamp are different)? – Daniel Rearden Mar 23 '19 at 23:34
  • The component is not being rerendered so I'm assuming the optimisticresponse is returning different data than what comes back from the server since the timestamp are different. – Grant Mar 24 '19 at 03:12
  • Differences between the optimistic response and the actual response shouldn't matter -- your component should still update once with the optimistic response and then again with the real one. Please update your question to include the code for the `Query` component that's not updating. It would also be helpful to see the full `Mutation` component too, and not just the optimisticResponse. – Daniel Rearden Mar 24 '19 at 03:39

0 Answers0