Which is Better GraphQL Client Libraries?
apollo-client vs urql vs react-apollo vs graphql-hooks
1 Year
apollo-clienturqlreact-apollographql-hooksSimilar Packages:
What's GraphQL Client Libraries?

GraphQL client libraries facilitate the interaction between a client application and a GraphQL server by providing tools for querying, mutating, and managing local state. They abstract the complexities of making network requests and handling responses, allowing developers to focus on building their applications. These libraries often come with features like caching, optimistic UI updates, and integration with state management solutions, enhancing the overall developer experience and application performance.

NPM Package Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
apollo-client420,38819,352-5184 years agoMIT
urql218,5498,631324 kB295 months agoMIT
react-apollo100,7576,852-2054 years agoMIT
graphql-hooks19,9341,882283 kB64 months agoApache-2.0
Feature Comparison: apollo-client vs urql vs react-apollo vs graphql-hooks

Caching

  • apollo-client: Apollo Client offers an advanced caching mechanism that allows for efficient data retrieval and state management. It supports normalized caching, where data is stored in a normalized format, enabling automatic updates and re-fetching of data when necessary. This results in improved performance and reduced network requests.
  • urql: Urql features a customizable caching layer that can be tailored to specific use cases. It supports both in-memory and persistent caching, allowing developers to choose the best strategy for their application. This flexibility makes it suitable for various application sizes and complexity.
  • react-apollo: React Apollo utilizes Apollo Client's caching capabilities, providing a seamless experience for managing data. It automatically updates the UI when data changes, thanks to its integration with Apollo's normalized cache, making it a robust choice for applications that require efficient data handling.
  • graphql-hooks: GraphQL Hooks does not provide built-in caching but allows developers to implement their own caching strategies. This gives developers flexibility but requires additional work to manage cache effectively, making it less suitable for applications that heavily rely on caching.

Integration with React

  • apollo-client: Apollo Client integrates deeply with React through the React Apollo library, providing hooks and higher-order components that simplify data fetching and state management in React applications. This integration allows for a more declarative approach to managing data in components.
  • urql: Urql offers a React-specific API with hooks that allow developers to fetch data easily within functional components. Its modular design means developers can choose which features to include, making it a flexible option for React applications.
  • react-apollo: React Apollo is the official integration of Apollo Client with React, providing a set of hooks and components that streamline data management in React applications. It allows developers to leverage Apollo's powerful features while maintaining a React-friendly syntax.
  • graphql-hooks: GraphQL Hooks is designed specifically for React, offering a simple hook-based API for making GraphQL requests. This makes it easy to integrate into existing React applications without additional boilerplate or complexity, promoting a clean and straightforward codebase.

Learning Curve

  • apollo-client: Apollo Client has a moderate learning curve due to its extensive features and configuration options. While it provides powerful capabilities, new users may need time to understand its caching strategies and how to best utilize its features in their applications.
  • urql: Urql has a relatively low learning curve due to its simple and modular design. Developers can start using it quickly, and its flexibility allows for gradual learning as they explore more advanced features.
  • react-apollo: React Apollo has a moderate learning curve, especially for developers who are already familiar with Apollo Client. The integration with React is intuitive, but understanding the full capabilities of Apollo, including caching and state management, may take some time.
  • graphql-hooks: GraphQL Hooks has a low learning curve, making it easy for developers to get started with GraphQL in React. Its straightforward API and minimal setup requirements allow for quick adoption, especially for those familiar with React hooks.

Flexibility and Customization

  • apollo-client: Apollo Client is highly flexible, allowing developers to customize caching strategies, link configurations, and more. However, this flexibility comes with added complexity, which may require a deeper understanding of the library's internals.
  • urql: Urql is built with flexibility in mind, allowing developers to customize its behavior and integrate it with various state management solutions. Its modular architecture enables users to include only the features they need, making it highly adaptable.
  • react-apollo: React Apollo inherits Apollo Client's flexibility, allowing for extensive customization and integration with other libraries. This makes it suitable for complex applications but may overwhelm developers who prefer simplicity.
  • graphql-hooks: GraphQL Hooks is designed to be minimalistic and straightforward, which limits customization options. Developers looking for a simple solution without extensive configuration will find it appealing, but those needing advanced features may find it lacking.
How to Choose: apollo-client vs urql vs react-apollo vs graphql-hooks
  • apollo-client: Choose Apollo Client if you need a comprehensive solution that includes advanced features like caching, local state management, and integration with React's context API. It's ideal for large applications that require sophisticated data handling and a robust ecosystem.
  • urql: Choose Urql if you want a highly customizable and flexible GraphQL client that can be tailored to your specific needs. It is designed to be lightweight and modular, making it suitable for applications that require fine-tuned performance and the ability to extend functionality easily.
  • react-apollo: Select React Apollo if you are already invested in the Apollo ecosystem and want to leverage its powerful features while using React. It provides a seamless way to integrate Apollo Client with React components, making it easier to manage data fetching and state in your application.
  • graphql-hooks: Opt for GraphQL Hooks if you prefer a lightweight and minimalistic approach to data fetching in React. It offers a simple API for making GraphQL queries and mutations, making it suitable for small to medium-sized applications that prioritize simplicity and ease of use.
README for apollo-client

Apollo Client npm version Open Source Helpers Join the community on Spectrum

Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to easily build UI components that fetch data via GraphQL. To get the most value out of apollo-client, you should use it with one of its view layer integrations.

To get started with the React integration, go to our React Apollo documentation website.

Apollo Client also has view layer integrations for all the popular frontend frameworks. For the best experience, make sure to use the view integration layer for your frontend framework of choice.

Apollo Client can be used in any JavaScript frontend where you want to use data from a GraphQL server. It's:

  1. Incrementally adoptable, so that you can drop it into an existing JavaScript app and start using GraphQL for just part of your UI.
  2. Universally compatible, so that Apollo works with any build setup, any GraphQL server, and any GraphQL schema.
  3. Simple to get started with, so you can start loading data right away and learn about advanced features later.
  4. Inspectable and understandable, so that you can have great developer tools to understand exactly what is happening in your app.
  5. Built for interactive apps, so your users can make changes and see them reflected in the UI immediately.
  6. Small and flexible, so you don't get stuff you don't need. The core is under 25kb compressed.
  7. Community driven, because Apollo is driven by the community and serves a variety of use cases. Everything is planned and developed in the open.

Get started on the home page, which has great examples for a variety of frameworks.

Installation

# installing the preset package
npm install apollo-boost graphql-tag graphql --save
# installing each piece independently
npm install apollo-client apollo-cache-inmemory apollo-link-http graphql-tag graphql --save

To use this client in a web browser or mobile app, you'll need a build system capable of loading NPM packages on the client. Some common choices include Browserify, Webpack, and Meteor 1.3+.

Install the Apollo Client Developer tools for Chrome for a great GraphQL developer experience!

Usage

You get started by constructing an instance of the core class ApolloClient. If you load ApolloClient from the apollo-boost package, it will be configured with a few reasonable defaults such as our standard in-memory cache and a link to a GraphQL API at /graphql.

import ApolloClient from 'apollo-boost';

const client = new ApolloClient();

To point ApolloClient at a different URL, add your GraphQL API's URL to the uri config property:

import ApolloClient from 'apollo-boost';

const client = new ApolloClient({
  uri: 'https://graphql.example.com'
});

Most of the time you'll hook up your client to a frontend integration. But if you'd like to directly execute a query with your client, you may now call the client.query method like this:

import gql from 'graphql-tag';

client.query({
  query: gql`
    query TodoApp {
      todos {
        id
        text
        completed
      }
    }
  `,
})
  .then(data => console.log(data))
  .catch(error => console.error(error));

Now your client will be primed with some data in its cache. You can continue to make queries, or you can get your client instance to perform all sorts of advanced tasks on your GraphQL data. Such as reactively watching queries with watchQuery, changing data on your server with mutate, or reading a fragment from your local cache with readFragment.

To learn more about all of the features available to you through the apollo-client package, be sure to read through the apollo-client API reference.

Learn how to use Apollo Client with your favorite framework


Contributing

CircleCI codecov

Read the Apollo Contributor Guidelines.

Running tests locally:

npm install
npm test

This project uses TypeScript for static typing and TSLint for linting. You can get both of these built into your editor with no configuration by opening this project in Visual Studio Code, an open source IDE which is available for free on all platforms.

Important discussions

If you're getting booted up as a contributor, here are some discussions you should take a look at:

  1. Static typing and why we went with TypeScript also covered in the Medium post
  2. Idea for pagination handling
  3. Discussion about interaction with Redux and domain vs. client state
  4. Long conversation about different client options, before this repo existed

Maintainers