Query: Fix data is undefined on error#1983
Conversation
If the query fails on the first result, the query result data was being returned as undefined Now this case will result in data being an empty object
|
@TLadd: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/ |
|
Thanks for working on this @TLadd! I agree with your assessment that the |
|
Using !data to check for errors would be pretty brittle anyways, since it only happens if there isn't already a previous result. Certainly could be possible that there is code out there depending on it though. |
|
The typings say Line 97 in 3985b47 So which one is it? |
|
Thanks for getting it across the finish line! |
| // like so result.data!.user. This tells TS to use TData | ||
| // XXX is there a better way to do this? | ||
| data: TData | undefined; | ||
| data: TData | {}; |
* master: (112 commits) chore(deps): update dependency danger to v3.8.8 chore(deps): update dependency enzyme to v3.5.0 chore(deps): update dependency apollo-client to v2.4.1 chore(deps): update dependency apollo-cache-inmemory to v1.2.9 chore(deps): update dependency apollo-cache to v1.1.16 chore(deps): update dependency @types/react to v16.4.12 chore(deps): update dependency rollup-plugin-commonjs to v9.1.6 chore(deps): update dependency @types/node to v10.9.2 chore(deps): update dependency react-scripts to v1.1.5 chore(deps): update dependency ts-jest to v23.1.4 Avoid importing lodash directly (apollographql#2045) type graphql.options.skip HOC property (apollographql#2208) Replace duplicate ObservableQueryFields types defined in apollo-client (apollographql#2281) Make mock links mock parameter readonly (apollographql#2284) test-utils: allow passing a custom cache object to `MockedProvider` (apollographql#2254) Query: Fix data is undefined on error (apollographql#1983) Don't mutate options object when calculating variables from props (apollographql#1968) Feature: add onSubscriptionData callback to <Subscription> (apollographql#1966) Changelog update Example of a mutation including tests (apollographql#1998) ...
|
Yes please, revert this change. It makes this VERY difficult to use in Typescript ;( |
|
@danilobuerger @tomitrescak Rolling back and we'll have a new release out this morning - thanks! |
|
So what ise the solution? Also the TypeScript example does not seem to work (any more) and it uses the old method of: examples/typescript/src/Character.tsx if (!data) return <div>no data</div>; |
|
@kallaspriit For now we'll roll this back, then we'll come up with another solution afterwards (we really didn't want breaking changes in this release). The examples are in the process of being updated and will be available shortly. We're also going to wire the example app tests into CI, to help keep them healthy. |
|
Wrote my comment seconds before seeing your reply. Sounds great :) |
|
This should be re-reverted. #2424 can be fixed by replacing data: TData | {};with data: Partial<TData>;Which is essentially the same, but don't break types. |
|
@fenok that is not true. Those are fundamentally different concepts and would validate very differently. Your example also allows partial objects, while the former allows only complete objects or empty objects |
|
Valid point, I was trapped in my partial results world. I also found that the idea of |
|
So, what's the current status of it? |
|
@evenfrost it was changed, but it's changed back from the previous change, which actually changed to keep things the same they were before the change, so that we don't really change what was changed before. Edit: jokes apart, current state is:
|
|
Thank you so much for clarifying, @lucasconstantino. I was getting really lost in trying to understand where things stand. 💫 Note, I just discovered that |
If the query fails on the first result, the query result data was being returned as undefined
Now this case will result in data being an empty object
Fixes #1977