apollo-client vs graphql-tag vs graphql-tools vs graphql.macro
GraphQL 相关库
apollo-clientgraphql-taggraphql-toolsgraphql.macro类似的npm包:

GraphQL 相关库

这些库用于简化 GraphQL 的使用和集成,提供了不同的功能和工具,以帮助开发者更高效地构建和管理 GraphQL API。它们各自的功能和用途不同,适用于不同的开发场景和需求。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
apollo-client019,725-4226 年前MIT
graphql-tag02,332-1004 年前MIT
graphql-tools05,4222.61 kB1533 个月前MIT
graphql.macro0238-287 年前MIT

功能对比: apollo-client vs graphql-tag vs graphql-tools vs graphql.macro

功能整合

  • apollo-client:

    Apollo Client 提供了强大的状态管理和缓存功能,可以与 React、Vue 和 Angular 等框架无缝集成。它允许开发者轻松管理本地和远程数据,支持实时更新和乐观更新。

  • graphql-tag:

    graphql-tag 主要用于定义 GraphQL 查询,它允许在 JavaScript 代码中使用模板字符串轻松编写查询。它的功能相对简单,适合快速开发和小型项目。

  • graphql-tools:

    graphql-tools 提供了一系列工具来构建和组合 GraphQL 架构。它支持类型定义、解析器组合和模拟数据,适合需要灵活架构的项目。

  • graphql.macro:

    graphql.macro 通过宏处理 GraphQL 查询,允许在编译时将查询嵌入到代码中,从而减少运行时的开销。它适合对性能敏感的应用程序,尤其是在大型项目中。

学习曲线

  • apollo-client:

    Apollo Client 的学习曲线相对较陡,尤其是对于初学者来说。它的功能丰富,涉及状态管理和缓存等高级概念,但一旦掌握,能够显著提高开发效率。

  • graphql-tag:

    graphql-tag 的学习曲线非常平缓,开发者只需了解如何使用模板字符串定义查询即可,非常适合初学者和小型项目。

  • graphql-tools:

    graphql-tools 的学习曲线适中,开发者需要理解 GraphQL 的基本概念和架构设计,但提供的工具可以帮助简化许多复杂的任务。

  • graphql.macro:

    graphql.macro 的学习曲线较低,开发者只需了解如何使用宏来处理查询,适合希望优化性能的开发者。

性能优化

  • apollo-client:

    Apollo Client 提供了多种缓存策略和优化选项,可以有效减少网络请求,提高应用性能。它的乐观更新和本地状态管理功能也能显著提升用户体验。

  • graphql-tag:

    graphql-tag 本身对性能的影响较小,但由于其简单性,能够快速编写和执行查询,适合需要快速响应的应用。

  • graphql-tools:

    graphql-tools 通过组合和重用解析器来优化性能,能够有效管理复杂的 GraphQL 架构,适合大型应用。

  • graphql.macro:

    graphql.macro 通过在编译时处理查询,减少了运行时的开销,从而提高了应用的整体性能,尤其是在大型项目中。

使用场景

  • apollo-client:

    Apollo Client 适合需要复杂数据管理的应用,如社交媒体、电子商务等,能够处理大量数据交互和实时更新。

  • graphql-tag:

    graphql-tag 适合小型项目或快速原型开发,能够快速定义和执行查询,适合对开发速度有较高要求的场景。

  • graphql-tools:

    graphql-tools 适合需要灵活架构设计的项目,能够帮助开发者构建可重用的类型和解析器,适合大型团队协作开发。

  • graphql.macro:

    graphql.macro 适合对性能有较高要求的应用,尤其是在大型项目中,能够显著减少运行时的查询处理开销。

社区支持

  • apollo-client:

    Apollo Client 拥有活跃的社区和丰富的文档支持,开发者可以轻松找到解决方案和最佳实践。

  • graphql-tag:

    graphql-tag 作为一个简单的库,社区支持相对较小,但由于其简单性,开发者可以快速上手。

  • graphql-tools:

    graphql-tools 拥有良好的社区支持,提供了丰富的文档和示例,适合需要深入学习 GraphQL 的开发者。

  • graphql.macro:

    graphql.macro 的社区支持相对较新,但随着对性能优化需求的增加,逐渐受到关注。

如何选择: apollo-client vs graphql-tag vs graphql-tools vs graphql.macro

  • apollo-client:

    选择 Apollo Client 如果你需要一个全面的解决方案来管理 GraphQL 数据,包括缓存、状态管理和网络请求。它非常适合需要复杂数据交互的应用程序。

  • graphql-tag:

    选择 graphql-tag 如果你需要在代码中方便地定义 GraphQL 查询和变更。它使得将查询嵌入到 JavaScript 代码中变得简单直观,适合小型项目或需要快速开发的场景。

  • graphql-tools:

    选择 graphql-tools 如果你需要构建和组合 GraphQL 架构。它提供了强大的工具来创建可重用的类型和解析器,适合需要灵活架构设计的项目。

  • graphql.macro:

    选择 graphql.macro 如果你希望在构建过程中自动处理 GraphQL 查询,减少运行时的开销。它适合对性能有较高要求的应用程序,尤其是在构建大型项目时。

apollo-client的README

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