Skip to content

Commit

Permalink
Task_1_Done
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandszoke committed Sep 19, 2019
1 parent a62640c commit f31e589
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
16 changes: 0 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"dependencies": {
"@apollo/react-components": "^3.1.1",
"@apollo/react-hooks": "^3.1.0",
"apollo-boost": "^0.4.4",
"apollo-cache-inmemory": "^1.6.3",
"apollo-client": "^2.6.4",
"apollo-link": "^1.2.13",
Expand Down
35 changes: 31 additions & 4 deletions src/apollo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
import ApolloClient from 'apollo-boost';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import { onError } from 'apollo-link-error';
import { ApolloLink } from 'apollo-link';

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

export default new ApolloClient({
uri: 'http://localhost:8000/graphql',
credentials: 'same-origin',
link: ApolloLink.from([
onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
graphQLErrors.forEach(({ message, locations, path }) => (
console.log(`[GraphQL error]: Message: ${message}, Location: ${JSON.stringify(locations)}, Path: ${path}`)
));
}
if (networkError) {
console.log(`[Network error]: ${networkError}`);
}
}),
globalLoader,
new HttpLink({
uri: 'http://localhost:8000/graphql',
credentials: 'same-origin',
}),
]),
cache: new InMemoryCache(),
});

0 comments on commit f31e589

Please sign in to comment.