import ApolloClient from 'apollo-client' ; import { HttpLink } from 'apollo-link-http' ; import { InMemoryCache } from 'apollo-cache-inmemory' ; import { createApolloFetch } from 'apollo-fetch' ; const fetch = createApolloFetch ( { uri : 'http://localhost:3000/graphql' } ) ; let apolloClient = null ; const proc = process as any ; const glob = global as any ; if ( ! proc . browser ) { glob . fetch = fetch ; } function create ( ) { return new ApolloClient ( { ssrMode : ! proc . browser , link : new HttpLink ( { uri : 'http://localhost:3000/graphql' , credentials : 'same-origin' } ) , cache : new InMemoryCache ( ) } ) ; } export function initApollo ( ) { if ( ! proc . browser ) { return create ( ) ; } if ( ! apolloClient ) { apolloClient = create ( ) ; } return apolloClient ; }