react-apollo
react-apollo copied to clipboard
Update onComplete handler typings
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.
@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/
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
@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 😬
@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)