Skip to content

Commit f31e589

Browse files
committed
Task_1_Done
1 parent a62640c commit f31e589

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

package-lock.json

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"dependencies": {
66
"@apollo/react-components": "^3.1.1",
77
"@apollo/react-hooks": "^3.1.0",
8-
"apollo-boost": "^0.4.4",
98
"apollo-cache-inmemory": "^1.6.3",
109
"apollo-client": "^2.6.4",
1110
"apollo-link": "^1.2.13",

src/apollo.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
1-
import ApolloClient from 'apollo-boost';
1+
import { ApolloClient } from 'apollo-client';
2+
import { InMemoryCache } from 'apollo-cache-inmemory';
3+
import { HttpLink } from 'apollo-link-http';
4+
import { onError } from 'apollo-link-error';
5+
import { ApolloLink } from 'apollo-link';
26

3-
// TODO: TASK 1. migrate from apollo-boost
7+
const globalLoader = new ApolloLink((operation, forward) => {
8+
// Use Mobx or Redux (or other) for a global state manager
9+
console.log('increment loading count');
10+
return forward(operation).map((response) => {
11+
console.log('decrement loading count');
12+
return response;
13+
});
14+
});
415

516
export default new ApolloClient({
6-
uri: 'http://localhost:8000/graphql',
7-
credentials: 'same-origin',
17+
link: ApolloLink.from([
18+
onError(({ graphQLErrors, networkError }) => {
19+
if (graphQLErrors) {
20+
graphQLErrors.forEach(({ message, locations, path }) => (
21+
console.log(`[GraphQL error]: Message: ${message}, Location: ${JSON.stringify(locations)}, Path: ${path}`)
22+
));
23+
}
24+
if (networkError) {
25+
console.log(`[Network error]: ${networkError}`);
26+
}
27+
}),
28+
globalLoader,
29+
new HttpLink({
30+
uri: 'http://localhost:8000/graphql',
31+
credentials: 'same-origin',
32+
}),
33+
]),
34+
cache: new InMemoryCache(),
835
});

0 commit comments

Comments
 (0)