Created
June 29, 2021 16:41
-
-
Save adhendo/83437761472f86e1b29073eb41cf73c8 to your computer and use it in GitHub Desktop.
apollo-client-setup
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 { 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