apollo-server-express vs @nestjs/graphql vs graphql-yoga vs express-graphql
GraphQL Server Libraries Comparison
3 Years
apollo-server-express@nestjs/graphqlgraphql-yogaexpress-graphql
What's GraphQL Server Libraries?

GraphQL Server Libraries are tools that help developers create GraphQL APIs in Node.js applications. These libraries provide the necessary infrastructure to define GraphQL schemas, handle queries and mutations, and integrate with existing web frameworks like Express. They vary in features, performance, and ease of use, catering to different use cases and developer preferences. Some popular GraphQL server libraries include Apollo Server, Express-GraphQL, and GraphQL Yoga, each offering unique capabilities for building efficient and scalable GraphQL APIs.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
apollo-server-express663,054
13,90527.6 kB682 years agoMIT
@nestjs/graphql649,966
1,508546 kB654 months agoMIT
graphql-yoga523,549
8,411285 kB166a month agoMIT
express-graphql263,759
6,298-555 years agoMIT
Feature Comparison: apollo-server-express vs @nestjs/graphql vs graphql-yoga vs express-graphql

Integration with Frameworks

  • apollo-server-express:

    apollo-server-express integrates seamlessly with Express.js, allowing developers to add a GraphQL server to their existing Express applications easily. It provides middleware that can be plugged into an Express app, making it flexible and easy to use.

  • @nestjs/graphql:

    @nestjs/graphql is designed specifically for NestJS, a progressive Node.js framework. It leverages NestJS's modular architecture, dependency injection, and decorators, making it a natural fit for applications built with NestJS.

  • graphql-yoga:

    graphql-yoga is built on top of Express (and other Node.js frameworks) but is designed to be framework-agnostic. It provides a simple API for creating a GraphQL server, making it easy to integrate into various projects.

  • express-graphql:

    express-graphql is a middleware for Express that allows you to create a GraphQL API quickly. It is lightweight and straightforward, making it easy to integrate into any existing Express application with minimal setup.

Feature Set

  • apollo-server-express:

    apollo-server-express is a feature-rich GraphQL server that supports subscriptions, file uploads, caching, and performance tracing. It also integrates with Apollo Client and provides tools for schema stitching and federation, making it suitable for complex applications.

  • @nestjs/graphql:

    @nestjs/graphql provides a rich set of features for building GraphQL APIs, including schema-first and code-first approaches, support for subscriptions, middleware, and integration with other NestJS modules. It is highly extensible and supports custom decorators and resolvers.

  • graphql-yoga:

    graphql-yoga comes with a comprehensive feature set, including support for subscriptions, file uploads, and real-time capabilities. It also includes built-in support for GraphQL Playground, making it easy to explore and test your API.

  • express-graphql:

    express-graphql offers the core features needed to create a GraphQL API, including support for queries, mutations, and subscriptions. However, it is more minimalistic compared to other libraries and does not include advanced features out of the box, allowing for greater flexibility and customization.

Ease of Setup

  • apollo-server-express:

    apollo-server-express is relatively easy to set up, especially for developers familiar with Express. It provides clear documentation and examples, making it straightforward to integrate into existing applications.

  • @nestjs/graphql:

    @nestjs/graphql requires a bit more setup due to its integration with the NestJS framework. However, once configured, it provides a highly structured and organized way to build GraphQL APIs, which can be beneficial for larger projects.

  • graphql-yoga:

    graphql-yoga is designed for quick setup and ease of use. It provides sensible defaults and a simple API, allowing developers to get a GraphQL server up and running in no time.

  • express-graphql:

    express-graphql is one of the easiest GraphQL libraries to set up. Its minimalistic design and straightforward API allow developers to quickly create a GraphQL endpoint with just a few lines of code.

Performance

  • apollo-server-express:

    apollo-server-express is optimized for performance, but its feature-rich nature can introduce some overhead. It is generally fast and efficient, especially when configured properly, but may require tuning for very high-load applications.

  • @nestjs/graphql:

    @nestjs/graphql performance largely depends on how well the NestJS application is structured. It is suitable for high-performance applications, but developers need to be mindful of the overhead introduced by the framework's features.

  • graphql-yoga:

    graphql-yoga offers good performance out of the box, but like any framework, it can be optimized further. Its design prioritizes speed and efficiency, making it suitable for most applications.

  • express-graphql:

    express-graphql is lightweight and has minimal overhead, making it one of the fastest GraphQL servers available. Its simplicity allows for quick execution of queries and mutations, making it ideal for performance-sensitive applications.

Code Example

  • apollo-server-express:

    Apollo Server with Express Example

    const express = require('express');
    const { ApolloServer, gql } = require('apollo-server-express');
    
    const typeDefs = gql`
      type Query {
        hello: String
      }
    `;
    
    const resolvers = {
      Query: {
        hello: () => 'Hello, world!',
      },
    };
    
    const server = new ApolloServer({ typeDefs, resolvers });
    const app = express();
    server.start().then(() => {
      server.applyMiddleware({ app });
      app.listen({ port: 4000 }, () => {
        console.log(`Server ready at http://localhost:4000${server.graphqlPath}`);
      });
    });
    
  • @nestjs/graphql:

    NestJS GraphQL Example

    import { Module } from '@nestjs/common';
    import { GraphQLModule } from '@nestjs/graphql';
    import { AppResolver } from './app.resolver';
    import { AppService } from './app.service';
    
    @Module({
      imports: [
        GraphQLModule.forRoot({
          autoSchemaFile: true,
        }),
      ],
      providers: [AppResolver, AppService],
    })
    export class AppModule {}
    
  • graphql-yoga:

    GraphQL Yoga Example

    const { createServer } = require('@graphql-yoga/node');
    
    const typeDefs = `
      type Query {
        hello: String
      }
    `;
    
    const resolvers = {
      Query: {
        hello: () => 'Hello, world!',
      },
    };
    
    const server = createServer({
      schema: {
        typeDefs,
        resolvers,
      },
    });
    
    server.start(() => {
      console.log('Server is running on http://localhost:4000');
    });
    
  • express-graphql:

    Express-GraphQL Example

    const express = require('express');
    const { graphqlHTTP } = require('express-graphql');
    const { buildSchema } = require('graphql');
    
    const schema = buildSchema(`
      type Query {
        hello: String
      }
    `);
    
    const root = {
      hello: () => 'Hello, world!',
    };
    
    const app = express();
    app.use('/graphql', graphqlHTTP({
      schema: schema,
      rootValue: root,
      graphiql: true,
    }));
    
    app.listen(4000, () => {
      console.log('Server is running on http://localhost:4000/graphql');
    });
    
How to Choose: apollo-server-express vs @nestjs/graphql vs graphql-yoga vs express-graphql
  • apollo-server-express:

    Select apollo-server-express if you need a feature-rich, standalone GraphQL server that integrates seamlessly with Express. It offers advanced features like caching, subscriptions, and Apollo Studio integration, making it suitable for both small and large applications.

  • @nestjs/graphql:

    Choose @nestjs/graphql if you are building a GraphQL API within a NestJS application and want to leverage its powerful module system, decorators, and dependency injection. It is ideal for large-scale applications that require a structured and maintainable architecture.

  • graphql-yoga:

    Choose graphql-yoga if you want an easy-to-use, full-featured GraphQL server that comes with sensible defaults and built-in support for subscriptions, file uploads, and more. It is great for developers who want a quick start with GraphQL without extensive configuration.

  • express-graphql:

    Opt for express-graphql if you want a minimalistic and lightweight solution for adding GraphQL to your existing Express app. It provides essential GraphQL functionality without any frills, allowing for quick setup and customization.

README for apollo-server-express

npm version Build Status Join the community forum Read CHANGELOG

This is the Express integration of Apollo Server. Apollo Server is a community-maintained open-source GraphQL server that works with many Node.js HTTP server frameworks. Read the docs. Read the CHANGELOG.

A full example of how to use apollo-server-express can be found in the docs.

Before Apollo Server 3, we officially supported using this package with connect as well. connect is an older framework that express evolved from. For now, we believe that this package is still compatible with connect and we even run tests against connect, but we may choose to break this compatibility at some point without a major version bump. If you rely on the ability to use Apollo Server with connect, you may wish to make your own integration.

Principles

GraphQL Server is built with the following principles in mind:

  • By the community, for the community: GraphQL Server's development is driven by the needs of developers
  • Simplicity: by keeping things simple, GraphQL Server is easier to use, easier to contribute to, and more secure
  • Performance: GraphQL Server is well-tested and production-ready - no modifications needed

Anyone is welcome to contribute to GraphQL Server, just read CONTRIBUTING.md, take a look at the roadmap and make your first PR!