Integrating with React Native


You can use Apollo Client with React Native exactly as you do with React.js. Install it with npm like so:

Bash
1npm install @apollo/client graphql

Then wrap your application in the ApolloProvider component, like so:

JavaScript
1import React from "react";
2import { AppRegistry } from "react-native";
3import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
4import { ApolloProvider } from "@apollo/client/react";
5
6// Initialize Apollo Client
7const client = new ApolloClient({
8  link: new HttpLink({ uri: "http://localhost:4000/graphql" }),
9  cache: new InMemoryCache(),
10});
11
12const App = () => (
13  <ApolloProvider client={client}>
14    <MyRootComponent />
15  </ApolloProvider>
16);
17
18AppRegistry.registerComponent("MyApplication", () => App);

For more information on setting up Apollo Client, see Getting started.

Example application

This sample application maintained by The GraphQL Guide uses Apollo Client with React Native.

Apollo Client Devtools

1. Using the VS Code Apollo GraphQL extension