Apollo Graphql Rest client in React Native
Oct 26, 2022
static getGQLClient() {
const httpLink = createHttpLink({
uri: Contants.BASE_URL_GQL,
});
const authLink = setContext((_, { headers }) => {
// get the authentication token from local storage if it exists
console.log('MY_TOKEN:::', MY_TOKEN)
const token = MY_TOKEN//'o3seez6dc9jygdb0i6nnqbsw9rgy5yqh' //'1fcc1s66v9vjhd3rsywr1p23oyht9pxu'// localStorage.getItem('token');
// if (MY_TOKEN) {
// token = String(MY_TOKEN)
// }
// return the headers to the context so httpLink can read them
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : "",
pincode: MY_PINCODE,
source: Platform.OS
}
}
});
//
const errorLink = onError(({ graphQLErrors, networkError, response }) => {
// console.log('response:', JSON.stringify(response))