Skip to content

Instantly share code, notes, and snippets.

@RyanCCollins
Last active February 18, 2017 18:04
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 RyanCCollins/32ac399958d0dc2a8c0dcb3449df2cd8 to your computer and use it in GitHub Desktop.
Save RyanCCollins/32ac399958d0dc2a8c0dcb3449df2cd8 to your computer and use it in GitHub Desktop.
import { ApolloClient, createNetworkInterface } from 'apollo-client';
declare var window: {
__APOLLO_STATE__: string,
};
const uri = process.env.API_URL || 'http://0.0.0.0:1338/api';
const client = new ApolloClient({
networkInterface: createNetworkInterface({
uri,
}),
initialState: typeof window !== 'undefined' ? window.__APOLLO_STATE__ : null, // eslint-disable-line
ssrForceFetchDelay: 100,
});
export default client;
import { combineReducers, Reducer } from 'redux';
import client from './apolloClient';
export const rootReducer = combineReducers({
apollo: client.reducer() as Reducer<any>,
});
import * as React from 'react';
import { ApolloProvider } from 'react-apollo';
import { Route, IndexRoute, Router as ReactRouter } from 'react-router';
import client from './apolloClient';
import store, { history } from './store';
export const routes = (
<Route path="/" component={App}>
<IndexRoute component={Home} />
// routes go here
</Route>
);
const RouterApp = () => (
<ApolloProvider store={store} client={client}>
<ReactRouter
onUpdate={logPage}
history={history}
routes={routes}
/>
</ApolloProvider>
);
export default RouterApp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment