apollo-client vs graphql-tag vs graphql-tools vs graphql.macro
GraphQL Client and Utility Libraries
apollo-clientgraphql-taggraphql-toolsgraphql.macroSimilar Packages:

GraphQL Client and Utility Libraries

These libraries are essential tools for working with GraphQL in JavaScript applications. They provide various functionalities that enhance the development experience, from managing GraphQL queries and mutations to simplifying the integration of GraphQL with React and other frameworks. Each library serves a unique purpose, catering to different aspects of GraphQL implementation, such as client-side data management, query parsing, schema building, and macro capabilities for cleaner code.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
apollo-client019,804-4096 years agoMIT
graphql-tag02,331175 kB983 months agoMIT
graphql-tools05,4322.64 kB1174 days agoMIT
graphql.macro0239-297 years agoMIT

Feature Comparison: apollo-client vs graphql-tag vs graphql-tools vs graphql.macro

Client-Side Management

  • apollo-client:

    Apollo Client excels in managing local and remote data with its powerful caching mechanism. It allows developers to seamlessly integrate GraphQL queries and mutations into their applications, providing a unified API for data fetching and state management. Its ability to handle optimistic UI updates and subscriptions makes it suitable for dynamic applications that require real-time data synchronization.

  • graphql-tag:

    graphql-tag does not manage data itself but serves as a utility to define GraphQL queries in a more readable format. It simplifies the process of embedding queries directly in your components, allowing you to keep your data-fetching logic close to where it is used without the need for additional management features.

  • graphql-tools:

    graphql-tools is focused on server-side schema management rather than client-side data management. It provides utilities for building GraphQL schemas, merging multiple schemas, and defining resolvers, making it essential for developers looking to create robust GraphQL APIs.

  • graphql.macro:

    graphql.macro enhances client-side management by allowing developers to write GraphQL queries as tagged template literals, which are then transformed at build time. This results in cleaner code and eliminates the need for string concatenation, improving the readability of data-fetching logic.

Ease of Use

  • apollo-client:

    Apollo Client is designed to be user-friendly, with extensive documentation and a strong community. Its integration with popular frameworks like React and Vue makes it easy to adopt, even for developers new to GraphQL. The API is intuitive, allowing for quick setup and effective data management without deep knowledge of GraphQL internals.

  • graphql-tag:

    graphql-tag is straightforward and easy to use, requiring minimal setup. It is particularly beneficial for developers who want to quickly define queries without the overhead of a full client library. Its simplicity makes it a great choice for smaller projects or when experimenting with GraphQL.

  • graphql-tools:

    graphql-tools has a steeper learning curve due to its focus on schema manipulation and server-side development. However, once mastered, it provides powerful capabilities for building and managing GraphQL schemas, making it invaluable for backend developers.

  • graphql.macro:

    graphql.macro is easy to integrate into existing projects and offers a simple syntax for writing queries. Its macro capabilities allow for cleaner code, but developers need to be familiar with the build process to leverage its full potential.

Performance

  • apollo-client:

    Apollo Client optimizes performance through its caching strategies, which reduce the number of network requests and improve loading times. It intelligently updates the cache based on the results of queries and mutations, ensuring that the UI reflects the latest data without unnecessary re-fetching.

  • graphql-tag:

    graphql-tag has minimal performance overhead since it only parses GraphQL queries. It does not include any data management features, which keeps the bundle size small and improves performance in applications where complex state management is not required.

  • graphql-tools:

    graphql-tools is efficient for schema manipulation but does not directly impact client-side performance. Its performance is primarily relevant in server-side contexts, where it helps streamline schema definitions and resolver implementations, leading to faster API responses.

  • graphql.macro:

    graphql.macro can enhance performance by reducing the size of the codebase through cleaner syntax. However, its impact on performance is more about code maintainability and readability than runtime efficiency.

Integration with Frameworks

  • apollo-client:

    Apollo Client integrates seamlessly with popular frameworks like React, Vue, and Angular, providing hooks and higher-order components that simplify data fetching and state management. This makes it a preferred choice for developers building modern web applications that require a strong connection between UI and data.

  • graphql-tag:

    graphql-tag is framework-agnostic and can be used with any JavaScript framework. Its simplicity allows it to be easily integrated into existing projects without the need for extensive modifications, making it versatile for various use cases.

  • graphql-tools:

    graphql-tools is primarily used in server-side applications and integrates well with Node.js and Express. It is not directly tied to any front-end framework, but it can be used alongside Apollo Server or other GraphQL server implementations to enhance schema management.

  • graphql.macro:

    graphql.macro is designed to work with modern JavaScript build tools and can be integrated into projects using Babel or Webpack. Its macro capabilities make it particularly useful in React applications, where it can simplify the way queries are written and managed.

Community and Support

  • apollo-client:

    Apollo Client has a large and active community, providing extensive documentation, tutorials, and support resources. This makes it easier for developers to find solutions to common problems and share knowledge, fostering a collaborative environment for learning and development.

  • graphql-tag:

    graphql-tag, being a utility library, has a smaller community compared to Apollo Client. However, it benefits from the broader GraphQL community, with many resources available for learning and troubleshooting.

  • graphql-tools:

    graphql-tools has a dedicated user base, especially among backend developers. While its community is not as large as Apollo Client's, it offers solid documentation and examples to help developers effectively use the library.

  • graphql.macro:

    graphql.macro is relatively new and has a smaller community. However, it is gaining traction among developers looking for cleaner syntax in their GraphQL queries, and its integration with popular build tools is well-documented.

How to Choose: apollo-client vs graphql-tag vs graphql-tools vs graphql.macro

  • apollo-client:

    Choose Apollo Client if you need a robust and feature-rich GraphQL client that supports caching, state management, and real-time updates through subscriptions. It is ideal for applications that require complex data handling and integration with React or other frameworks.

  • graphql-tag:

    Select graphql-tag if you want a lightweight solution for parsing GraphQL queries directly in your JavaScript code. It is particularly useful for embedding queries in your components without the overhead of a full client library, making it a great choice for simple applications or when you want to keep your bundle size small.

  • graphql-tools:

    Opt for graphql-tools when you need to build and manipulate GraphQL schemas programmatically. It is perfect for creating mock data, merging multiple schemas, or defining resolvers, making it a go-to choice for server-side development and schema management.

  • graphql.macro:

    Use graphql.macro if you prefer a more concise syntax for writing GraphQL queries within your JavaScript files. It allows you to leverage the power of macros to avoid string literals, improving code readability and maintainability, especially in large codebases.

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