Skip to content

Instantly share code, notes, and snippets.

@PaulRBerg
Created January 21, 2020 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulRBerg/8c97f854d4334dd8f73f4d3224bb7b91 to your computer and use it in GitHub Desktop.
Save PaulRBerg/8c97f854d4334dd8f73f4d3224bb7b91 to your computer and use it in GitHub Desktop.
Function that creates an instance of Apollo Client
import typy from "typy";
import { ApolloClient } from "apollo-client";
import { HttpLink } from "apollo-link-http";
import { InMemoryCache } from "apollo-cache-inmemory";
import cacheRedirects from "./cacheRedirects";
import resolvers from "./resolvers";
import typeDefs from "./typeDefs";
export default function createClient(chainName = "") {
/* By default, we display the data on mainnet */
let uri;
if (typy(chainName).isFalsy || chainName === "mainnet") {
uri = process.env.REACT_APP_APOLLO_HTTP_URL;
} else {
uri = process.env.REACT_APP_APOLLO_HTTP_URL + "-" + chainName;
}
return new ApolloClient({
cache: new InMemoryCache({
cacheRedirects,
}),
link: new HttpLink({ uri }),
resolvers,
typeDefs,
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment