Registry / web-framework / react-apollo

react-apollo

JSON →
library3.1.5jsnpmunverified

React Apollo (package `react-apollo`) provided the official React integration for Apollo Client, enabling developers to fetch and manage GraphQL data in React applications using Hooks, Components, and Higher-Order Components (HOCs). Version 3.1.5, released on April 14, 2020, was a stable release within the v3 series. The project has since been officially deprecated, with version 4.0.0 (released July 20, 2020) being its final release. All core React Apollo functionality, including hooks, components, HOCs, SSR, and testing utilities, has been migrated directly into the `@apollo/client` package (v3 and above). Developers are strongly advised to migrate to `@apollo/client` for active maintenance, new features, and bug fixes, as `react-apollo` no longer receives updates or support.

npm install react-apollo
INSTALL
IMPORT
SIG · REACT-APOLLO
R
react-apollo
web-frameworkjavascriptv3.1.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ApolloProvider
import { ApolloProvider } from 'react-apollo';
const ApolloProvider = require('react-apollo').ApolloProvider;
Required to provide an ApolloClient instance to the React component tree. Since Apollo Client 3+, this should be imported from `@apollo/client/react`.
Query
import { Query } from 'react-apollo';
import Query from 'react-apollo/Query';
A React component for declarative data fetching. For Apollo Client 3+, this is available from `@apollo/client/react/components`.
useQuery
import { useQuery } from 'react-apollo';
import { useQuery } from '@apollo/react-hooks';
A React hook for executing GraphQL queries. This functionality is now directly available from `@apollo/client` since Apollo Client 3.x. The separate `@apollo/react-hooks` package is also deprecated.
graphql
import { graphql } from 'react-apollo';
import graphql from 'react-apollo/lib/graphql';
The higher-order component (HOC) for injecting GraphQL data into components. For Apollo Client 3+, this is available from `@apollo/client/react/hoc`.

This quickstart demonstrates how to set up `react-apollo` with `ApolloClient`, define a GraphQL query using `gql`, and fetch data in a React component using the `useQuery` hook. It renders a list of todos from a public API.

import React from 'react'; import ReactDOM from 'react-dom'; import { ApolloClient, InMemoryCache, HttpLink } from 'apollo-client'; import { ApolloProvider, useQuery, gql } from 'react-apollo'; // Create an Apollo Client instance const client = new ApolloClient({ link: new HttpLink({ uri: 'https://graphqlzero.almansi.me/api', }), cache: new InMemoryCache(), }); // Define your GraphQL query const GET_TODOS = gql` query GetTodos { todos(options: { limit: 5 }) { data { id title completed } } } `; // A React component that uses the useQuery hook function Todos() { const { loading, error, data } = useQuery(GET_TODOS); if (loading) return <p>Loading todos...</p>; if (error) return <p>Error: {error.message}</p>; return ( <div> <h2>My Todos (via react-apollo)</h2> <ul> {data.todos.data.map(({ id, title, completed }) => ( <li key={id} style={{ textDecoration: completed ? 'line-through' : 'none' }}> {title} </li> ))} </ul> </div> ); } // Render the application wrapped in ApolloProvider ReactDOM.render( <ApolloProvider client={client}> <Todos /> </ApolloProvider>, document.getElementById('root') );
Debug
Known issues
breakingThe `react-apollo` package is officially deprecated and archived. Version 4.0.0 was the final release. All future development, bug fixes, and features are integrated directly into the `@apollo/client` package (version 3 and above). Continuing to use `react-apollo` means using an unsupported library.
fix
Migrate your application to `@apollo/client`. Refer to the Apollo Client migration guide for detailed instructions. This involves updating imports from `react-apollo` or `@apollo/react-hooks` to `@apollo/client` and its subpaths (e.g., `@apollo/client/react/components`, `@apollo/client/react/hoc`).
affects: >=4.0.0
breakingVersion 3.0.0 introduced significant breaking changes, including a minimum React version requirement of 16.8. The `react-apollo` package primarily re-exports functionality from `@apollo/react-hooks`, `@apollo/react-components`, and `@apollo/react-hoc`. Testing utilities were moved to `@apollo/react-testing`.
fix
Ensure your React version is 16.8 or newer. For components and hooks, consider direct imports from the `@apollo/react-X` packages or, preferably, migrate to `@apollo/client` directly. Update testing utility imports to `@apollo/react-testing`.
affects: >=3.0.0 <4.0.0
breakingA breaking change was introduced in `useLazyQuery` in versions 3.1.5, potentially altering its behavior or API.
fix
Review your `useLazyQuery` implementations when upgrading to 3.1.5. Consult the GitHub issues (#4040) for specific changes and potential workarounds, or migrate to `@apollo/client` which has its own `useLazyQuery` implementation.
affects: 3.1.5
gotchaVersions 3.1.4 and 3.1.5 were reported to break `addMocksToSchema` functionality from `@graphql-tools/mock` when used with `MockedProvider`.
fix
If experiencing issues with `MockedProvider` and `@graphql-tools/mock`, consider downgrading `react-apollo` to an earlier 3.x version (e.g., 3.1.3) or migrating your testing setup entirely to `@apollo/client` and its testing utilities (`@apollo/client/testing`).
affects: 3.1.4, 3.1.5
gotchaUsing `setState` within the `onError` or `onCompleted` callbacks of the `Query` component (and potentially `useQuery` hook) could lead to infinite loops in earlier versions (2.5.3). This pattern can still be problematic if not carefully managed.
fix
Ensure `setState` calls in `onCompleted` or `onError` are guarded to prevent re-renders that re-trigger the query/mutation. For example, check if `data` or `error` has changed before updating state, or use a ref to track if a side effect has already been performed.
affects: >=2.5.3
Errors
Common errors & fixes
Error: Could not find "client" in the context of ApolloConsumer. Wrap the root component in an <ApolloProvider>.
The ApolloClient instance was not provided to the React context, usually because the root component is not wrapped with `<ApolloProvider />` or the client prop is missing.
fix
Ensure your application's root component (or the highest common ancestor of your GraphQL components) is wrapped in `<ApolloProvider client={yourApolloClientInstance}>...</ApolloProvider>`.
TypeError: Cannot destructure property 'data' of 'undefined' or 'null'.
This often happens when `useQuery` returns `undefined` for `data` (or `loading`/`error` properties) before the query has completed or if `useQuery` itself is returning `undefined` as reported in issue #4042 for v3.x.
fix
Always check for `loading` and `error` states before trying to access `data`. For specific issues like #4042, consider upgrading or downgrading `react-apollo` to a working version or, preferably, migrating to `@apollo/client`.
GraphQL error: Network error: Failed to fetch
The client could not connect to the GraphQL server, often due to an incorrect URI, network issues, or CORS policy blocks.
fix
Verify the `uri` in your `HttpLink` configuration is correct and accessible. Check browser console for CORS errors. Ensure your GraphQL server is running and reachable.
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application.
A GraphQL operation (query, mutation, subscription) completes after the component that initiated it has unmounted, leading to state updates on an unmounted component.
fix
Use a ref to track component mounted status or implement cleanup logic (e.g., in `useEffect` for hooks, `componentWillUnmount` for classes) to cancel pending operations or prevent state updates if the component is unmounted.
Unhandled Rejection (Error): A breaking change in 3.1.5 affects useLazyQuery
Specific breaking changes in `useLazyQuery` were reported for `react-apollo` 3.1.5, causing unexpected behavior or errors.
fix
Review the usage of `useLazyQuery` in your application. Consult GitHub issues (e.g., #4040) for details on the breaking change. Consider pinning to an earlier `react-apollo` 3.x version or migrating to `@apollo/client` which provides its own `useLazyQuery` hook.
Upgrade
Version history
3.1.5latest on npm
Audit
Dependencies
@types/reactoptionalTypeScript type definitions for React components.
apollo-clientrequiredCore GraphQL client for data fetching, caching, and state management.
graphqlrequiredGraphQL language utilities and schema definitions.
reactrequiredRequired for building React components and utilizing hooks.
react-domrequiredProvides DOM-specific methods for React applications.
Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
react-apollo — npm install react-apollo · libregistry