Created
September 6, 2019 13:28
-
-
Save kevotovar/a6f101edc63d15b6e15537d83c8faad1 to your computer and use it in GitHub Desktop.
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
import { HttpLink, ApolloClient, InMemoryCache } from "apollo-boost"; | |
import { AsyncStorage } from "react-native"; | |
import { setContext } from "apollo-link-context"; | |
const httpLink = new HttpLink({ uri: "http://localhost:8000/graphql/" }); | |
const authLink = setContext(async (req, { headers }) => { | |
const token = await AsyncStorage.getItem("authToken"); | |
return { | |
...headers, | |
headers: { | |
authorization: token ? `JWT ${token}` : null | |
} | |
}; | |
}); | |
const link = authLink.concat(httpLink); | |
const client = new ApolloClient({ | |
link, | |
cache: new InMemoryCache() | |
}); | |
export default client; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment