Welcome to the first exercise in the React Track of this Apollo Client Tutorial! If you prefer React Native, Angular 2 or Vue.js over React, head over to the respective tutorial track.
The goal of this first exercise is to install a React App and run it afterwards. You will get familiar with the infrastructure surrounding Apollo Client for React and with the app structure of the Pokedex.
We will see a generic greeting in our pokedex at the end of this exercise:

Sign up with GitHub to receive your own pokedex-react here:
Now change to the first exercise, install the dependencies and start the app from your console
cd pokedex-react/exercise-01
yarn install # or npm install
yarn start # or npm start
Let's take a moment to get more familiar with the structure of the app.
The starting point for our app is src/index.js. At the moment, all that happens here is setting up the router to render the Pokedex component for the / route path:
ReactDOM.render((
<Router history={browserHistory}>
<Route path='/' component={Pokedex} />
</Router>
),
document.getElementById('root')
)
We can add Apollo Client to our app by adding the following changes to src/index.js.
Open package.json to have a look what packages we are using.
apollo-client - the core package exposes the vanilla JS Apollo Client which provides the core functionalityreact-apollo - the React integration exposes the ApolloProvider that can be used to wrap other React components, allowing them to send queries and mutationsNow go ahead and import the following at the top of src/index.js:
COPY THIS SNIPPET
copy to src/index.js
import ApolloClient, { createNetworkInterface } from 'apollo-client' import { ApolloProvider } from 'react-apollo'
Now we can connect Apollo Client with our GraphQL server by configuring the network layer. Paste the following right after the imports in src/index.js:
COPY THIS SNIPPET
copy to src/index.js
const client = new ApolloClient({ networkInterface: createNetworkInterface({ uri: 'https://api.graph.cool/simple/v1/__PROJECT_ID__'}), })
If you signed up with GitHub and downloaded the example, we already took care of this step for the following exercises.
To allow our React components to issue GraphQL queries and mutations through the client we wrap them with the ApolloProvider component in src/index.jsfrom the react-apollo package. Go ahead and update the call to ReactDOM.render in src/index.js:
COPY THIS SNIPPET
copy to src/index.js
ReactDOM.render(( <ApolloProvider client={client}> <Router history={browserHistory}> <Route path='/' component={Pokedex} /> </Router> </ApolloProvider> ), document.getElementById('root') )
As we are using react-router to handle our routes, we wrap the Router component. Note that the / route points to the Pokedex component.
Note: You don't have to put
ApolloProvideron the highest level of the component hierarchy - however, every component that wants to use Apollo Client needs to be a direct or indirect child ofApolloProviderin the component hierarchy.
Our Pokedex component lives in src/components/Pokedex.js. Currently, it only contains a generic greeting, but that will change soon! We will further expand this component in the following exercises to give an overview about all the pokemon in your pokedex as well as the possibility to add new pokemons or update existing ones. But for now, let's make sure you are ready to go.
To confirm your environment is all correctly setup, open http://localhost:3000 in your browser and you should see the greeting from the Pokedex component.
Great, you did it! You successfully ran the React app and got familiar with its general structure. Let's quickly summarize what we learned so far:
apollo-client and setup its networkInterfacereact-apollo