question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router Resolve does not work with Apollo

See original GitHub issue

I’m trying to use apollo.watchQuery to resolve data in router:

import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
import { Apollo } from 'apollo-angular';
import { DocumentNode } from 'graphql';
import gql from 'graphql-tag/index';

import { Account } from '../../models/account';

const accountResolverQuery: DocumentNode = gql`
  query AccountResolverQuery($accountId: String!) {
    account(id: $accountId) {
      id
      name
      address {
        city
        line1
        line2
        postalCode
        region
      }
    }
  }
`;

interface AccountResolverQueryResponse {
  account: Account;
}

@Injectable()
export class AccountResolver implements Resolve<Account> {
  constructor(private apollo: Apollo) {
  }

  resolve(route: ActivatedRouteSnapshot): Observable<Account> {
    const accountId = route.params['id'];

    return this.apollo
      .watchQuery<AccountResolverQueryResponse>({
        query: accountResolverQuery,
        variables: {
          accountId,
        },
      })
      .map(({ data }: { data: AccountResolverQueryResponse }) => data.account);
  }
}

But it just does not work. Apollo makes request, but navigation just does nothing. Any other observable works (like using REST).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
kamilkisielacommented, Feb 10, 2017

@longuniquename There is a different between watchQuery and query methods. Second one behaves the same as those from Angular’s Http service.

What I mean by that?

With query() you fetch data, receive the result, then an Observable completes. With watchQuery() you fetch data, receive the result and an Observable is keep opened for new emissions so it never completes.

Try to use query() instead of watchQuery in this kind of scenarios.

3reactions
longuniquenamecommented, Feb 10, 2017

@kamilkisiela It worked! Thank you, for your help and for your work 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Router Resolve does not work with Apollo · Issue #280 - GitHub
I'm trying to use apollo.watchQuery to resolve data in router: import { ActivatedRouteSnapshot, Resolve } from '@angular/router'; ...
Read more >
Configuring the Apollo Router - Apollo GraphQL Docs
You run the Apollo Router with the following command (assuming you're in the same ... By default, the router does not resolve introspection...
Read more >
Angular Resolver -resolving data from HTTP call is not working
I'm trying to resolve data from HTTP call from graphql apollo client. The data does not get resolved and the component using the...
Read more >
How to Reset Universal Audio Apollo Interfaces - Sweetwater
Read this article to learn how to reset your Universal Audio USB, Firewire, or Thunderbolt Apollo audio interface back to factory settings.
Read more >
Resolve 15—UAD Apollo Audio Interface not working as output
So back to Resolve: When the Audio is set to 'Custom', it picks up exactly that WDM routing or at least, can select...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found