ApolloClient: ObservableQuery.map/.filter/.reduce/.flatMap don't work
See original GitHub issueIntended outcome:
I’d like to use the basic zen-observable methods like map
and filter
to pipe the results of a query through some transformations before subscribing to it.
apolloClient.watchQuery({ query })
.map(result => transformResult(result))
.subscribe(console.log);
The docs say “Refer to the zen-observable documentation for additional context and API options.” — I read that as the standard zen-observable API should be available and cooperate with the ObservableQuery API.
Actual outcome:
Calling any of the above methods cause runtime errors that look like:
/sandbox/node_modules/apollo-client/bundle.umd.js:146
_this.variables = options.variables || {};
^
TypeError: Cannot read property 'variables' of undefined
The actual line of code where the error occurs is here.
How to reproduce the issue:
Reproduction: https://codesandbox.io/embed/apollo-client-observable-query-map-509cw
zen-observable seems to support subclassing, but it assumes that the subclass constructor has the same signature. This creates two problems:
- When
.map
creates a new ObservableQuery, it doesn’t know about the constructor’squeryManager
,options
, andshouldSubscribe
arguments. - Even after I hacked in support for
new ObservableQuery(fn)
, the new observable returned from.map
doesn’t have a query manager so ObservableQuery’s methods likerefetch
do not work.
Versions
apollo-client@2.6.4
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:9
Top GitHub Comments
@hwillson Do we have a sense if this might be address in AC3?
What works for me: