kamilkisiela / apollo-client-rxjs

Adds RxJS to ApolloClient
http://apollostack.com
43 stars 12 forks source link

TypeError: Cannot read property 'initStore' of undefined #50

Open stalniy opened 7 years ago

stalniy commented 7 years ago

Steps:

  1. Use RxApolloClient class
  2. Watch query with variables apollo.watchQuery({ query, variables })

Actual result Exception is thrown: core.es5.js:1084 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'initStore' of undefined TypeError: Cannot read property 'initStore' of undefined at ApolloClient.watchQuery (ApolloClient.js:179) at SwitchMapSubscriber.project (variables.js:14) at SwitchMapSubscriber._next (switchMap.js:88) at SwitchMapSubscriber.Subscriber.next (Subscriber.js:89) at SafeSubscriber._next

Expected result No errors

Context: digging into source code I see that watchQuery is passed without bound "this" context. That's why after calling it, function throws an error

stalniy commented 7 years ago

The code needs to be changed to super.watchQuery.bind(this) or (...args) => super.watchQuery(...args)

kamilkisiela commented 6 years ago

If you use apollo-angular then we changed the way ApolloClient works with RxJS. You can check it here: apollographql/apollo-angular#377

No more this kind of issues.