Apollo Hooks

It is now time to get some real data from the server. Remember Health? Let's display the result on a page using Apollo Hooks.

~/packages/web
$ yarn add apollo-boost react-apollo apollo-client graphql apollo-utilities apollo-cache apollo-link

Update App.tsx to use ApolloProvider:

import React from "react";
import ApolloClient from "apollo-boost";
import { ApolloProvider } from "react-apollo";
import "./App.css";
import { LinksPage } from "./pages/links";

const client = new ApolloClient({ uri: "/graphql" });

const App: React.FC = () => {
  return (
    <ApolloProvider client={client}>
      <div className="App">
        <LinksPage />
      </div>
    </ApolloProvider>
  );
};

export default App;

To tell the development server to proxy any unknown requests to your API server in development, add a proxy field to your package.json:

Make sure the server is running.

Update LinksPages to query Health:

We can send request to our GrapqhQL API. Now we need to add user authentication.

apollo-hooks branch available on GitHub.

Last updated

Was this helpful?