Created
October 7, 2018 10:54
-
-
Save TrillCyborg/85e7c30b93f5942742ad6b9df9934cc1 to your computer and use it in GitHub Desktop.
Accounts.js / Apollo Client Boilerplate for authenticated resolvers
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 } from "apollo-client"; | |
import { ApolloLink } from "apollo-link"; | |
import { createHttpLink } from "apollo-link-http"; | |
import { InMemoryCache } from "apollo-cache-inmemory"; | |
import { AccountsClient } from "@accounts/client"; | |
import { AccountsClientPassword } from "@accounts/client-password"; | |
import GraphQLClient from "@accounts/graphql-client"; | |
import { accountsLink } from "@accounts/apollo-link"; | |
let uri = /* gql endpoint */; | |
const cache = new InMemoryCache(); | |
const httpLink = createHttpLink({ | |
uri | |
}); | |
export const graphQLApolloClient = new ApolloClient({ | |
link: ApolloLink.from([httpLink]), | |
cache | |
}); | |
export const accountsGraphQL = new GraphQLClient({ | |
graphQLClient: graphQLApolloClient | |
}); | |
export const accountsClient = new AccountsClient({}, accountsGraphQL); | |
export const accountsPassword = new AccountsClientPassword(accountsClient); | |
const authLink = accountsLink(accountsClient); | |
const apolloClient = new ApolloClient({ | |
link: ApolloLink.from([authLink, httpLink]), | |
cache | |
}); | |
export default apolloClient; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment