kamilkisiela / apollo-client-rxjs

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

Apollo Observable chaining not working #24

Closed fischerman closed 7 years ago

fischerman commented 7 years ago

From https://github.com/apollostack/apollo-client/issues/1207

Whenever I chain the result of watchQuery only the last observable in the chain get's invoked. The following returns only 3, but 1 and 2 are missing.

this.apollo.watchQuery({...})
.do(() => {
    console.log(1)
})
.do(() => {
    console.log(2);
})
.do(() => {
    console.log(3);
})
.subscribe() `

To compare the following returns the expected 1,2,3

Observable.range(1,1)
.do(() => {
    console.log(1)
})
.do(() => {
    console.log(2);
})
.do(() => {
    console.log(3);
})
.subscribe() 

Am I missing something or is this a bug?

rxjs@5.0.0-rc.4 angular2-apollo@0.9.0-rc.5 apollo-client-rxjs@0.4.0

fischerman commented 7 years ago

The solution @calebmer suggested (wrapping the watchQuery in an Observable.from) does not work. Same behavior.

kamilkisiela commented 7 years ago

@fischerman I will take a look on that. Observable.from is good but you loose all the methods of ApolloObservableQuery, so you cannot use watchQuery etc.

fischerman commented 7 years ago

Thanks @kamilkisiela

Just to clarify:

Observable.from(this.apollo.watchQuery({...}))
.do(() => {
    console.log(1)
})
.do(() => {
    console.log(2);
})
.do(() => {
    console.log(3);
})
.subscribe()

does NOT fix the issue. Same result: 3

Can you think of a workaround?

kamilkisiela commented 7 years ago

Try not to use the Angular2Apollo service, instead of that, use a clear instance of ApolloClient. this.apollo.watchQuery means that you're using ApolloClient that has been wrapped with RxJS (a part of apollo-client-rxjs).

an example:

const client: ApolloClient = ...;

Observable.from(client.watchQuery({...}))
.do.do.do;
kamilkisiela commented 7 years ago

@fischerman seems like it's working... hmmm

Take a look at #28

fischerman commented 7 years ago

When I find the time I will try to reproduce my behavior in a Plunker. The workaround you suggested works for now.

fischerman commented 7 years ago

@kamilkisiela can't reproduce

it works with the latest angular-cli and apollo-angular