Skip to content

Instantly share code, notes, and snippets.

@adhendo
Created June 29, 2021 16:41
Show Gist options
  • Save adhendo/83437761472f86e1b29073eb41cf73c8 to your computer and use it in GitHub Desktop.
Save adhendo/83437761472f86e1b29073eb41cf73c8 to your computer and use it in GitHub Desktop.
apollo-client-setup
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
import { offsetLimitPagination } from "@apollo/client/utilities";
import { setContext } from "@apollo/link-context";
import { GRAPHQL_API_URL } from "react-native-dotenv";
import Firebase from "./firebase";
const asyncAuthLink = setContext(async () => {
return {
headers: {
Authorization: `Bearer ${await Firebase.auth().currentUser.getIdToken()}`,
},
};
});
const httpLink = new HttpLink({
uri: GRAPHQL_API_URL,
});
export const apolloClient = new ApolloClient({
cache: new InMemoryCache(
{
typePolicies: {
Query: {
fields: {
feed:
offsetLimitPagination()
}
}
}
}
),
link: asyncAuthLink.concat(httpLink),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment