kamilkisiela / apollo-client-rxjs

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

Cannot read property 'subscribeToMore' of undefined #37

Open longuniquename opened 7 years ago

longuniquename commented 7 years ago

Hi,

When I try to subscribe on updates like this:

this.data = this.apollo
  .watchQuery({
    query: controllersListQuery,
    variables: {
      accountId: this.accountId,
      status: this.status,
      oemId: this.oemId,
      search: this.search,
    },
  });

this.data.subscribeToMore({
  document: gql`
    subscription OnCreateController($accountId: ID!) {
      controllerCreated(accountId: $accountId) {
        id
      }
    }
  `,
  variables: {
    accountId: '896ae9dd-7aed-4e5f-88d7-e93acd331f0c',
  },
  updateQuery: (previousResult, { subscriptionData, variables }) => {
    console.log(previousResult, subscriptionData, variables);
    return previousResult;
  },
  onError: (err) => console.error(err),
});

I get an error: Cannot read property 'subscribeToMore' of undefined. As I see at some point in this place getRef() returns object without ref:

private getObservableQuery(): ObservableQuery<T> {
  if (this.apollo instanceof ObservableQueryRef) {
    const ref = this.apollo as ObservableQueryRef;
    return ref.getRef();
  }

  return this.apollo as ObservableQuery<T>;
}

and when it tries to subscribeToMore() here:

public subscribeToMore(options: any): () => void {
  return this.getObservableQuery().subscribeToMore(options);
}

ref is undefined.

Thanks in advance for any help and big thanks for your work on this package!

Stradivario commented 6 years ago

So from feb there is no one from the developers which can say how to use SubscribeToMore correct ?

b-barry commented 6 years ago

PR #51 merged

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.