-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return undefined for result.data if no data is available #4356
Conversation
Just re-capping the discussion we had in Slack about this - we're a bit worried about backwards compatibility with regards to adjusting the types of
and I like it! So 👍 on this approach @danilobuerger - thanks! |
70bac32
to
c902fe7
Compare
c902fe7
to
397139e
Compare
@hwillson Implemented at discussed. This is now ready for review. After merge, I will take care of react-apollo side to use this new API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @danilobuerger - looks great!
So far, the docs specify the following:
https://www.apollographql.com/docs/react/api/react-apollo.html#query-render-prop However, this change seems to have shipped and then reverted due to a breaking change for TS users: apollographql/react-apollo#1983 (comment) I can't believe there's no simple way to tell TS that an object can be "empty" by default, and I really don't get it... take in mind that for people like me AKA end users who are using JavaScript, it's definitely worse to have data defaults to Anyway, I guess the docs should be fixed? Thanks! |
😕
|
There is a simple way to tell TypeScript (
The library should be useable by both JavaScript and TypeScript users. We fell that this is a good compromise for both worlds. If you have a better idea which works for both worlds, we would really like to hear about it. Also, I don't really see the argument for JavaScript. If you do
Yes. Thanks for reporting it. |
Thanks for the quick reply! I'll try to elaborate more later (sorry, already unavailable right now) on why having {} instead of undefined would be a better default (it involves nested Query components using the skip option). |
@nuragic Sure, but please not here. This is a closed, merged PR. Not a place to discuss this. If you like, please open a feature request at https://github.com/apollographql/apollo-feature-requests |
This is to align with react-apollo and the decision that data should be
TData | undefined
instead ofTData | {}
.Ref:
Related: