Router Resolve does not work with Apollo
See original GitHub issueI’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:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@longuniquename There is a different between
watchQuery
andquery
methods. Second one behaves the same as those from Angular’sHttp
service.What I mean by that?
With
query()
you fetch data, receive the result, then an Observable completes. WithwatchQuery()
you fetch data, receive the result and an Observable is keep opened for new emissions so it never completes.Try to use
query()
instead ofwatchQuery
in this kind of scenarios.@kamilkisiela It worked! Thank you, for your help and for your work 😃