dotansimha / dotansimha/graphql-code-generator-community
[typescript-react-apollo] withHooks: using `returnPartialData` should make all returned fields optional
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
**Is your feature request related to a problem? Please describe.**
We are using the `typescript-react-apollo` plugin along with the `withHooks` option.
The problem is that when the hook is called with [`returnPartialData`](https://www.apollographql.com/docs/react/data/queries/#returnpartialdata), some fields in the response might be `undefined` due to a cached value that does not include newly added fields.
**Describe the solution you'd like**
It would be great if the typings would take this option into account and make the returned type something like `Partial<...>`
**Describe alternatives you've considered**
I tried these config options but none of them alter the field types of the returned query data:
```
maybeValue: T | undefined
wrapEntireFieldDefinitions: true
fieldWrapperValue: Maybe
entireFieldWrapperValue: Maybe
defaultMapper: Maybe
resolverTypeWrapperSignature: Maybe
inlineFragmentTypes: combine
```
**Additional context**
I'm loading a list of events, in React-Native.
```js
const { data, loading } = useEventsQuery({
fetchPolicy: "cache-and-network",
notifyOnNetworkStatusChange: true,
returnPartialData: true,
});
const events = data?.events || [];
events.forEach((event) => {
console.log(event.name); // type should be `string | undefined`, even though Event["name"] is a string
console.log(event.infos.address); // throws an Error if `name` is cached but not `infos`
});
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.