Skip to content

Instantly share code, notes, and snippets.

@TrillCyborg
Created October 7, 2018 10:54
Show Gist options
  • Save TrillCyborg/85e7c30b93f5942742ad6b9df9934cc1 to your computer and use it in GitHub Desktop.
Save TrillCyborg/85e7c30b93f5942742ad6b9df9934cc1 to your computer and use it in GitHub Desktop.
Accounts.js / Apollo Client Boilerplate for authenticated resolvers
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