Created
January 21, 2020 18:58
-
-
Save PaulRBerg/8c97f854d4334dd8f73f4d3224bb7b91 to your computer and use it in GitHub Desktop.
Function that creates an instance of Apollo Client
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 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