apollo icon indicating copy to clipboard operation
apollo copied to clipboard

onDone typing for data includes null | undefined

Open P4sca1 opened this issue 3 years ago • 3 comments

Describe the bug The typing of result.data in the onDone event hook (returned by useMutation and useQuery) is MyResult | null | undefined.

To Reproduce

const { mutate, onDone } = useMutation(MyTypedDocument)

onDone((result) => {
  // The type of result.data is `MyResult | null | undefined`
})

Expected behavior

onDone: Event hook called when the mutation successfully completes.

I would expect that a successfull mutation / query cannot return null | undefined unless the GraphQL response type is nullable (which it is not in my case).

Versions vue: 2.6.14 vue-apollo: 4.0.0-alpha.16 @apollo/client: 3.5.8

P4sca1 avatar Feb 09 '22 13:02 P4sca1

I also have the same logic problem. But maybe that's intended?

ThibaultNocchi avatar Mar 24 '22 10:03 ThibaultNocchi

That would imply that onDone is called when a response is not successful, which afaik is not the case.

P4sca1 avatar Mar 24 '22 11:03 P4sca1

I agree. I hope someone will see that and fix it :)

ThibaultNocchi avatar Mar 24 '22 14:03 ThibaultNocchi