graphql-yoga vs apollo-server-express vs express-graphql
GraphQL 服务器库
graphql-yogaapollo-server-expressexpress-graphql

GraphQL 服务器库

GraphQL 服务器库提供了构建和管理 GraphQL API 的工具和框架。这些库允许开发者快速创建可扩展的 API,支持复杂的数据查询和变更操作。它们各自具有不同的特性和设计理念,适用于不同的开发需求和场景。选择合适的库可以提高开发效率、简化数据处理流程,并增强应用的可维护性。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
graphql-yoga1,027,3238,505298 kB1331 天前MIT
apollo-server-express013,94327.6 kB822 年前MIT
express-graphql06,289-555 年前MIT

功能对比: graphql-yoga vs apollo-server-express vs express-graphql

功能丰富性

  • graphql-yoga:

    GraphQL Yoga 提供了许多开箱即用的功能,如实时订阅、文件上传和自定义中间件,旨在简化 GraphQL API 的构建过程。

  • apollo-server-express:

    Apollo Server 提供了丰富的功能,包括数据源集成、缓存、实时订阅和错误处理。它支持多种数据源,如 REST API 和数据库,允许开发者轻松构建复杂的 GraphQL API。

  • express-graphql:

    Express-GraphQL 提供基本的 GraphQL 功能,支持简单的查询和变更操作,但缺乏高级功能,如数据源集成和缓存。适合简单的应用场景。

易用性

  • graphql-yoga:

    GraphQL Yoga 的设置非常简单,适合快速原型开发,提供了默认配置和最佳实践,帮助开发者快速上手。

  • apollo-server-express:

    Apollo Server 的文档详细且易于理解,提供了大量示例和最佳实践,适合新手和经验丰富的开发者。

  • express-graphql:

    Express-GraphQL 的使用非常简单,适合快速集成到现有的 Express 应用中,但可能需要更多的手动配置来实现复杂功能。

社区支持

  • graphql-yoga:

    GraphQL Yoga 也拥有一个活跃的社区,提供了许多示例和支持,适合快速开发和学习。

  • apollo-server-express:

    Apollo Server 拥有一个活跃的社区和丰富的生态系统,提供了大量的插件和工具,支持开发者的各种需求。

  • express-graphql:

    Express-GraphQL 作为一个轻量级的解决方案,社区支持相对较小,但仍然有足够的资源和文档可供参考。

性能

  • graphql-yoga:

    GraphQL Yoga 通过内置的优化和配置,能够提供良好的性能,适合中小型应用。

  • apollo-server-express:

    Apollo Server 在性能上表现优异,支持数据缓存和批处理请求,能够处理高并发的查询和变更操作。

  • express-graphql:

    Express-GraphQL 的性能取决于实现,适合简单的查询,但在处理复杂查询时可能需要额外的优化。

扩展性

  • graphql-yoga:

    GraphQL Yoga 提供了灵活的扩展选项,允许开发者通过中间件和自定义配置来满足特定需求。

  • apollo-server-express:

    Apollo Server 提供了高度的扩展性,允许开发者通过插件和中间件轻松扩展功能,适合大型应用。

  • express-graphql:

    Express-GraphQL 的扩展性较低,适合简单的 API,但在需要复杂功能时可能需要更多的手动实现。

如何选择: graphql-yoga vs apollo-server-express vs express-graphql

  • graphql-yoga:

    选择 GraphQL Yoga 如果你需要一个开箱即用的解决方案,提供了许多开箱即用的功能,如实时订阅和文件上传。它适合快速原型开发和小型到中型项目。

  • apollo-server-express:

    选择 Apollo Server Express 如果你需要一个功能强大的 GraphQL 服务器,支持多种数据源集成、缓存管理和订阅功能。它适合需要复杂数据处理和灵活架构的应用。

  • express-graphql:

    选择 Express-GraphQL 如果你希望轻量级的解决方案,能够快速集成到现有的 Express 应用中。它适合简单的 GraphQL API,特别是当你已经在使用 Express 时。

graphql-yoga的README

GraphQL Yoga

Fully-featured GraphQL Server with focus on easy setup, performance & great developer experience
Go to documentation

npm bundlephobia minified size bundlephobia minified+zipped size bundlephobia treeshaking license

Quick start

Install

pnpm add graphql-yoga graphql

Start

Make a schema, create Yoga and start a Node server:

import { createServer } from 'node:http'
import { createSchema, createYoga } from 'graphql-yoga'

const yoga = createYoga({
  schema: createSchema({
    typeDefs: /* GraphQL */ `
      type Query {
        hello: String
      }
    `,
    resolvers: {
      Query: {
        hello: () => 'Hello from Yoga!'
      }
    }
  })
})

const server = createServer(yoga)

server.listen(4000, () => {
  console.info('Server is running on http://localhost:4000/graphql')
})

Overview

  • Easiest way to run a GraphQL server: Sensible defaults & includes everything you need with minimal setup (we also export a platform/env-agnostic handler so you can build your own wrappers easily).
  • Includes Subscriptions: Built-in support for GraphQL subscriptions using Server-Sent Events.
  • Compatible: Works with all GraphQL clients (Apollo, Relay, Urql...) and fits seamless in your GraphQL workflow.
  • WHATWG Fetch API: the core package depends on WHATWG Fetch API so it can run and deploy on any environment (Serverless, Workers, Deno, Node).
  • Easily Extendable: New GraphQL-Yoga support all envelop plugins.

Features

Documentation

Our documentation website will help you get started.

Examples

We've made sure developers can quickly start with GraphQL Yoga by providing a comprehensive set of examples. See all of them in the examples/ folder.

Comparison

Read more about how GraphQL Yoga compares to other servers in the ecosystem here.

Contributing

If this is your first time contributing to this project, please do read our Contributor Workflow Guide before you get started off.

For this project in particular, to get started on stage/2-failing-test:

  1. Install Node.js
  2. Run in your terminal: npm i -g pnpm@8 && pnpm install && pnpm build
  3. Add tests to packages/graphql-yoga/__tests__ using Jest APIs
  4. Run the tests with pnpm test

Feel free to open issues and pull requests. We're always welcome support from the community.

Code of Conduct

Help us keep Yoga open and inclusive. Please read and follow our Code of Conduct as adopted from Contributor Covenant.

License

MIT