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.

`NetworkStatus.loading` available globally on `ApolloClient`?

See original GitHub issue

Is there any way to determine whether NetworkStatus.loading is true for any currently executing ApolloClient operation?

I’d like to create an application-wide network activity indicator component in an Apollo-Angular project without having each Apollo client .query/.watchQuery/.mutate call report its NetworkStatus.loading. I thought of using middleware/afterware hooks in ApolloClientConfig.networkInterface, but since the Apollo client is configured in the AppModule decorator, it’s not easy to construct a hook that would report Apollo network activity in a way that would be available to an Angular component via an injected service.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
KeithGillettecommented, Oct 30, 2017

Thanks so much! With the help of the apollo-client and angular-apollo migration guides, the howtographql/angular-apollo example, and @kamilkisiela’s expert guidance, I got our project upgraded to ApolloClient 2.0.1 + Angular-Apollo 1.0.0 with apollo-angular-link-http. I successfully tested a third-party Angular network activity/loading component that intercepts Angular HttpClient used by apollo-angular-link-http, so for now I’ll leave my custom link writing to the one I needed for Meteor authentication with apollo-angular-link-http:

const meteorAuthenticationMiddleWareLink = new ApolloLink((operation: Operation, forward: NextLink): Observable<FetchResult> => {
	const meteorAuthenticationToken = Accounts._storedLoginToken();
	if (meteorAuthenticationToken) {
		const headers = new HttpHeaders({'meteor-login-token': Accounts._storedLoginToken()});
		operation.setContext({headers});
	}
	return forward(operation);
});
1reaction
kamilkisielacommented, Oct 29, 2017

@KeithGillette that’s great! Thanks to using HttpClient we gain so many things like NativeScript support, SSR, features like that one you mentioned! If you have any questions feel free to message me on slack (same user handle)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling operation errors - Apollo GraphQL Docs
Apollo Client can encounter a variety of errors when executing operations ... const { loading, error, data } = useQuery(MY_QUERY, { errorPolicy: "all"...
Read more >
Global Loading Flag for Apollo Client - Stack Overflow
I've just released a library that solves this for Apollo 2: react-apollo-network-status. The gist is: import React, {Fragment} from 'react'; ...
Read more >
react-apollo-network-status - npm package - Snyk
Brings information about the global network status from Apollo into React. This library helps with implementing global loading indicators like progress bars or ......
Read more >
Optimistic UIs with React, Apollo Client and TypeScript (Part I)
To make the Apollo Client instance available throughout the entire ... current user globally available to the application's component tree.
Read more >
How to set up a React Apollo client with a Graphcool GraphQL ...
Apollo Client is a GraphQL client (alternative to Relay) that can be used with ... Error: fetch is not found globally and no...
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