@apollo/server vs @nestjs/graphql vs graphql-yoga vs express-graphql
GraphQL Server Libraries Comparison
1 Year
@apollo/server@nestjs/graphqlgraphql-yogaexpress-graphqlSimilar Packages:
What's GraphQL Server Libraries?

GraphQL server libraries provide the necessary tools and frameworks to build GraphQL APIs, enabling efficient data fetching and manipulation through a single endpoint. They facilitate the creation of schemas, resolvers, and middleware, allowing developers to define the structure of their data and how it can be accessed. Each library has unique features and design philosophies that cater to different use cases, from full-fledged frameworks to lightweight solutions, making it essential to choose the right one based on project requirements and team familiarity.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
@apollo/server1,203,82313,8531.96 MB952 months agoMIT
@nestjs/graphql597,8451,490546 kB5115 days agoMIT
graphql-yoga486,0278,320273 kB152a day agoMIT
express-graphql266,9626,319-554 years agoMIT
Feature Comparison: @apollo/server vs @nestjs/graphql vs graphql-yoga vs express-graphql

Integration

  • @apollo/server:

    @apollo/server provides deep integration with Apollo Client, allowing for advanced features like caching and state management, making it ideal for applications that require complex data handling.

  • @nestjs/graphql:

    @nestjs/graphql integrates seamlessly with the NestJS framework, leveraging its modular architecture and dependency injection, which promotes code organization and reusability.

  • graphql-yoga:

    graphql-yoga is a standalone server that can be easily integrated with various frameworks and libraries, providing a flexible setup for developers looking for a quick and efficient GraphQL solution.

  • express-graphql:

    express-graphql is designed to work with Express.js, making it easy to add GraphQL capabilities to existing Express applications without requiring a complete overhaul of the app's architecture.

Features and Flexibility

  • @apollo/server:

    @apollo/server offers a rich set of features including built-in support for subscriptions, middleware, and performance tracing, making it suitable for complex applications that require extensive functionality.

  • @nestjs/graphql:

    @nestjs/graphql provides decorators and a modular approach, allowing developers to easily define schemas and resolvers while maintaining a clean code structure, making it flexible for large-scale applications.

  • graphql-yoga:

    graphql-yoga comes with sensible defaults and built-in support for features like subscriptions and file uploads, making it user-friendly and flexible for developers who want to get started quickly.

  • express-graphql:

    express-graphql is lightweight and minimal, focusing on providing the core functionalities needed to implement GraphQL, which allows developers to customize their setup as needed without unnecessary bloat.

Learning Curve

  • @apollo/server:

    @apollo/server has a moderate learning curve, especially for developers unfamiliar with Apollo's ecosystem. However, its extensive documentation and community support can help ease the onboarding process.

  • @nestjs/graphql:

    @nestjs/graphql may have a steeper learning curve due to its reliance on NestJS concepts like decorators and modules, but it rewards developers with a structured and maintainable codebase.

  • graphql-yoga:

    graphql-yoga is designed for quick adoption, with minimal configuration required. Its simplicity makes it ideal for beginners or those looking to prototype applications rapidly.

  • express-graphql:

    express-graphql is straightforward and easy to learn, making it an excellent choice for developers who are already familiar with Express.js and want to add GraphQL capabilities without much overhead.

Performance

  • @apollo/server:

    @apollo/server is optimized for performance with features like batching and caching, which can significantly reduce the number of requests made to the server and improve response times.

  • @nestjs/graphql:

    @nestjs/graphql benefits from NestJS's performance optimizations and can handle complex applications efficiently, especially when using TypeScript for type safety and clarity.

  • graphql-yoga:

    graphql-yoga is built for performance with features like automatic persisted queries and subscriptions, making it suitable for real-time applications that demand quick responses.

  • express-graphql:

    express-graphql is lightweight and performs well for smaller applications, but may require additional optimizations for larger datasets or complex queries to maintain performance.

Community and Ecosystem

  • @apollo/server:

    @apollo/server has a large and active community, providing a wealth of resources, plugins, and integrations that enhance its functionality and ease of use.

  • @nestjs/graphql:

    @nestjs/graphql is part of the NestJS ecosystem, which has been rapidly growing, offering a supportive community and numerous modules that can be leveraged for various use cases.

  • graphql-yoga:

    graphql-yoga has a smaller but dedicated community, focusing on ease of use and rapid development, making it a good choice for developers looking for straightforward support.

  • express-graphql:

    express-graphql has a solid community due to its simplicity and integration with Express, but it may not have as many advanced features or plugins compared to more comprehensive solutions.

How to Choose: @apollo/server vs @nestjs/graphql vs graphql-yoga vs express-graphql
  • @apollo/server:

    Choose @apollo/server if you are looking for a robust and feature-rich GraphQL server that integrates seamlessly with Apollo Client, providing advanced features like caching, subscriptions, and a powerful developer toolset.

  • @nestjs/graphql:

    Select @nestjs/graphql if you are already using NestJS or prefer a modular architecture with TypeScript support. It leverages decorators and dependency injection, making it suitable for building scalable server-side applications.

  • graphql-yoga:

    Choose graphql-yoga if you need a zero-config GraphQL server that supports subscriptions out of the box and is designed for ease of use. It's great for rapid prototyping and development, especially for teams looking for a simple setup.

  • express-graphql:

    Opt for express-graphql if you want a minimalistic and straightforward solution that integrates easily with existing Express applications. It's ideal for small projects or when you need to quickly set up a GraphQL endpoint without additional overhead.

README for @apollo/server

@apollo/server

This @apollo/server package is new with Apollo Server 4. Previous major versions of Apollo Server used a set of package names starting with apollo-server, such as apollo-server, apollo-server-express, apollo-server-core, etc.

npm version Build Status Join the community


Announcement: Join 1000+ engineers at GraphQL Summit for talks, workshops, and office hours, Oct 8-10 in NYC. Get your pass here ->


A TypeScript/JavaScript GraphQL server

Apollo Server is an open-source, spec-compliant GraphQL server that's compatible with any GraphQL client, including Apollo Client. It's the best way to build a production-ready, self-documenting GraphQL API that can use data from any source.

You can use Apollo Server as:

Apollo Server provides a simple API for integrating with any Node.js web framework or serverless environment. The @apollo/server package itself ships with a minimally-configurable, standalone web server which handles CORS and body parsing out of the box. Integrations with other environments are community-maintained.

Apollo Server provides:

  • Straightforward setup, so your client developers can start fetching data quickly
  • Incremental adoption, enabling you to add features as they're needed
  • Universal compatibility with any data source, any build tool, and any GraphQL client
  • Production readiness, enabling you to confidently run your graph in production

Documentation

Full documentation for Apollo Server is available on our documentation site. This README shows the basics of getting a server running (both standalone and with Express), but most features are only documented on our docs site.

Getting started: standalone server

You can also check out the getting started guide in the Apollo Server docs for more details, including examples in both TypeScript and JavaScript.

Apollo Server's standalone server lets you get a GraphQL server up and running quickly without needing to set up an HTTP server yourself. It allows all the same configuration of GraphQL logic as the Express integration, but does not provide the ability to make fine-grained tweaks to the HTTP-specific behavior of your server.

First, install Apollo Server and the JavaScript implementation of the core GraphQL algorithms:

npm install @apollo/server graphql

Then, write the following to server.mjs. (By using the .mjs extension, Node lets you use the await keyword at the top level.)

import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';

// The GraphQL schema
const typeDefs = `#graphql
  type Query {
    hello: String
  }
`;

// A map of functions which return data for the schema.
const resolvers = {
  Query: {
    hello: () => 'world',
  },
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
});

const { url } = await startStandaloneServer(server);
console.log(`🚀 Server ready at ${url}`);

Now run your server with:

node server.mjs

Open the URL it prints in a web browser. It will show Apollo Sandbox, a web-based tool for running GraphQL operations. Try running the operation query { hello }!

Getting started: Express middleware

Apollo Server's built-in Express middleware lets you run your GraphQL server as part of an app built with Express, the most popular web framework for Node.

First, install Apollo Server, the JavaScript implementation of the core GraphQL algorithms, Express, and two common Express middleware packages:

npm install @apollo/server graphql express cors body-parser

If using Typescript you may also need to install additional type declaration packages as development dependencies to avoid common errors when importing the above packages (i.e. Could not find a declaration file for module 'cors'):

npm install --save-dev @types/cors @types/express @types/body-parser

Then, write the following to server.mjs. (By using the .mjs extension, Node lets you use the await keyword at the top level.)

import { ApolloServer } from '@apollo/server';
import { expressMiddleware } from '@apollo/server/express4';
import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer'
import express from 'express';
import http from 'http';
import cors from 'cors';
import bodyParser from 'body-parser';

// The GraphQL schema
const typeDefs = `#graphql
  type Query {
    hello: String
  }
`;

// A map of functions which return data for the schema.
const resolvers = {
  Query: {
    hello: () => 'world',
  },
};

const app = express();
const httpServer = http.createServer(app);

// Set up Apollo Server
const server = new ApolloServer({
  typeDefs,
  resolvers,
  plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
});
await server.start();

app.use(
  cors(),
  bodyParser.json(),
  expressMiddleware(server),
);

await new Promise((resolve) => httpServer.listen({ port: 4000 }, resolve));
console.log(`🚀 Server ready at http://localhost:4000`);

Now run your server with:

node server.mjs

Open the URL it prints in a web browser. It will show Apollo Sandbox, a web-based tool for running GraphQL operations. Try running the operation query { hello }!