Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'subscribeToMore' of undefined #37

Open
longuniquename opened this issue Feb 23, 2017 · 3 comments
Open

Cannot read property 'subscribeToMore' of undefined #37

longuniquename opened this issue Feb 23, 2017 · 3 comments

Comments

@longuniquename
Copy link

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
Copy link

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

@b-barry
Copy link
Contributor

b-barry commented Sep 23, 2017

PR #51 merged

@kamilkisiela
Copy link
Owner

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

No more this kind of issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants