-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a62640c
commit f31e589
Showing
3 changed files
with
31 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}); |