Skip to content

Instantly share code, notes, and snippets.

@nanlabsweb
Created March 20, 2018 19:28
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 nanlabsweb/4f7a7c99c3729d1b1bb81bbeceebaee9 to your computer and use it in GitHub Desktop.
Save nanlabsweb/4f7a7c99c3729d1b1bb81bbeceebaee9 to your computer and use it in GitHub Desktop.
How to setup Apollo Client library in a React app.
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { ApolloProvider } from 'react-apollo';
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
const client = new ApolloClient({
link: new HttpLink({ uri: 'http://localhost:5010/graphql' }),
cache: new InMemoryCache()
});
ReactDOM.render(
<ApolloProvider client={client}>
<BrowserRouter>
<App/>
</BrowserRouter>
</ApolloProvider>,
document.getElementById('root')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment