react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

Update onComplete handler typings

Open ghost opened this issue 5 years ago • 4 comments

Fixes #3546

Checklist:

  • N/A – If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • N/A – Make sure all of the significant new logic is covered by tests
  • N/A – If this was a change that affects the external API used in GitHunt-React, update GitHunt-React and post a link to the PR in the discussion.

ghost avatar Oct 30 '19 15:10 ghost

@SophieDonut: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

apollo-cla avatar Oct 30 '19 15:10 apollo-cla

I have been bitten by TypeError: undefined is not an object too many times because Typescript can't help me remember to check if this is undefined

Please someone merge this

vieiralucas avatar Nov 11 '19 20:11 vieiralucas

@hwillson Would it be possible to get this merged?

We're getting frequent crashes due to onCompleted getting called with data being undefined when the type system says it shouldn't 😬

richeterre avatar Jan 13 '20 16:01 richeterre

@SophieDonut Now that the dev of the client is happening on the apollo-client repository, I think you have little chance of you're PR getting reviewed.

In the v3.0 beta doc, I see this about the onCompleted handler (on the useQuery/useMutation hooks) :

onCompleted | (data: TData | {}) => void | A callback executed once your query successfully completes.

So it seems that data can't be really undefined but just an empty object. So you'll need to test your root attributs for being defined before doing anything with them. It makes sense with what we observed on our apps (but we have big issues trying to repro it)

victorlevasseur avatar Jan 30 '20 11:01 victorlevasseur