apollo-server vs express-graphql vs graphql vs graphql-yoga
GraphQL Server Libraries
apollo-serverexpress-graphqlgraphqlgraphql-yogaSimilar Packages:

GraphQL Server Libraries

GraphQL server libraries provide the necessary tools to create and manage GraphQL APIs, allowing developers to define schemas, handle queries, and manage data fetching efficiently. These libraries facilitate the implementation of GraphQL specifications, enabling clients to request only the data they need, which can lead to more efficient data retrieval and improved performance. Each library has its unique features and use cases, catering to different development needs and preferences.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
apollo-server259,49313,95026.6 kB792 years agoMIT
express-graphql06,291-555 years agoMIT
graphql020,3311.41 MB1324 days agoMIT
graphql-yoga08,493294 kB1282 days agoMIT

Feature Comparison: apollo-server vs express-graphql vs graphql vs graphql-yoga

Ease of Use

  • apollo-server:

    Apollo Server is designed to be easy to set up and use, with a focus on developer experience. It provides a comprehensive set of features out of the box, including schema stitching, caching, and support for subscriptions, making it suitable for both beginners and experienced developers.

  • express-graphql:

    Express-GraphQL is straightforward to integrate into existing Express applications. It requires minimal configuration and allows developers to quickly expose a GraphQL API without much overhead, making it ideal for smaller projects or those already using Express.

  • graphql:

    GraphQL itself is a specification rather than a library, so its ease of use depends on the implementation. Understanding the core concepts of GraphQL can be straightforward, but building a server from scratch requires more effort and familiarity with the underlying technologies.

  • graphql-yoga:

    GraphQL Yoga offers a very user-friendly setup process, with sensible defaults that allow developers to get started quickly. It abstracts many complexities, making it an excellent choice for those who want to focus on building features rather than configuration.

Features and Extensibility

  • apollo-server:

    Apollo Server is highly extensible, allowing developers to add custom directives, middleware, and plugins. It supports advanced features like data sources for efficient data fetching and built-in support for Apollo Client, making it a powerful choice for complex applications.

  • express-graphql:

    Express-GraphQL is lightweight and does not impose many features, which can be a benefit for developers looking for simplicity. However, it may require additional libraries or custom implementations for features like subscriptions or advanced error handling.

  • graphql:

    As a specification, GraphQL does not provide features itself, but it allows for extensive customization in implementations. Developers can define their own types, queries, and mutations, which can lead to highly tailored solutions but requires more effort to implement.

  • graphql-yoga:

    GraphQL Yoga combines the best features of Apollo Server and Express-GraphQL, providing a rich set of features while remaining easy to use. It supports subscriptions, file uploads, and real-time capabilities, making it a versatile choice for modern applications.

Community and Support

  • apollo-server:

    Apollo Server has a large and active community, providing extensive documentation, tutorials, and third-party tools. This support can be invaluable for developers looking to implement complex features or troubleshoot issues.

  • express-graphql:

    Express-GraphQL has a smaller community compared to Apollo Server, but it is well-documented and supported by the Express.js community. It may not have as many resources, but it remains a reliable choice for those familiar with Express.

  • graphql:

    Being the core specification, GraphQL has a vast community and a wealth of resources available. However, support may vary depending on the specific implementation chosen by the developer.

  • graphql-yoga:

    GraphQL Yoga benefits from a growing community and is backed by the GraphQL community at large. It provides good documentation and examples, making it easier for new developers to adopt.

Performance

  • apollo-server:

    Apollo Server is optimized for performance with features like caching and batching, which can significantly reduce the number of requests made to the server. It also provides tools for monitoring performance and tracing queries, helping developers optimize their APIs.

  • express-graphql:

    Express-GraphQL is lightweight and can perform well for small to medium-sized applications. However, it may require additional optimization techniques for larger applications, as it does not come with built-in performance enhancements like Apollo Server.

  • graphql:

    Performance depends on the implementation of the GraphQL server. Developers have full control over how to optimize data fetching and processing, but this requires a deeper understanding of performance best practices.

  • graphql-yoga:

    GraphQL Yoga is designed for performance and scalability, offering built-in features for handling subscriptions and real-time data. It is suitable for applications that expect high traffic and require efficient data handling.

Learning Curve

  • apollo-server:

    Apollo Server has a moderate learning curve, especially for developers new to GraphQL. However, its extensive documentation and community resources can help ease the learning process, making it accessible for most developers.

  • express-graphql:

    Express-GraphQL has a gentle learning curve, especially for those already familiar with Express.js. Its simplicity allows developers to quickly grasp the basics of GraphQL and start building APIs without much overhead.

  • graphql:

    Learning GraphQL itself can be straightforward, but implementing a server requires understanding both the specification and the chosen library's features. This can present a steeper learning curve for beginners.

  • graphql-yoga:

    GraphQL Yoga is designed to be beginner-friendly, with a focus on simplicity and ease of use. Its sensible defaults and comprehensive documentation make it an excellent choice for developers new to GraphQL.

How to Choose: apollo-server vs express-graphql vs graphql vs graphql-yoga

  • apollo-server:

    Choose Apollo Server if you need a robust, feature-rich GraphQL server that integrates seamlessly with various data sources, supports middleware, and offers advanced features like caching, subscriptions, and performance tracing. It is particularly well-suited for applications that require a comprehensive GraphQL solution with extensive community support.

  • express-graphql:

    Choose Express-GraphQL if you are already using Express.js and want a lightweight, straightforward way to add GraphQL capabilities to your existing Express application. It provides a simple setup and is ideal for projects that prioritize minimalism and direct integration with Express middleware.

  • graphql:

    Choose GraphQL if you are looking for the core specification and want to build your own GraphQL server from scratch. This package provides the fundamental tools needed to define schemas and types, making it suitable for developers who prefer custom implementations or want to learn the inner workings of GraphQL.

  • graphql-yoga:

    Choose GraphQL Yoga if you want an easy-to-use, fully-featured GraphQL server that comes with sensible defaults and a focus on developer experience. It is built on top of Express and Apollo Server, making it a great choice for rapid development and prototyping while still being capable of handling production workloads.

README for apollo-server

Apollo Server

A TypeScript GraphQL Server for Express, Koa, Hapi, Lambda, and more.

npm version Build Status Join the community forum Read CHANGELOG

Apollo Server is a community-maintained open-source GraphQL server. It works with many Node.js HTTP server frameworks, or can run on its own with a built-in Express server. Apollo Server works with any GraphQL schema built with GraphQL.js--or define a schema's type definitions using schema definition language (SDL).

Read the documentation for information on getting started and many other use cases and follow the CHANGELOG for updates.

Principles

Apollo Server is built with the following principles in mind:

  • By the community, for the community: Its development is driven by the needs of developers.
  • Simplicity: By keeping things simple, it is more secure and easier to implement and contribute.
  • Performance: It is well-tested and production-ready.

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

Getting started

To get started with Apollo Server:

  • Install with npm install apollo-server-<integration> graphql
  • Write a GraphQL schema
  • Use one of the following snippets

There are two ways to install Apollo Server:

  • Standalone: For applications that do not require an existing web framework, use the apollo-server package.
  • Integrations: For applications with a web framework (e.g. express, koa, hapi, etc.), use the appropriate Apollo Server integration package.

For more info, please refer to the Apollo Server docs.

Installation: Standalone

In a new project, install the apollo-server and graphql dependencies using:

npm install apollo-server graphql

Then, create an index.js which defines the schema and its functionality (i.e. resolvers):

const { ApolloServer, gql } = require('apollo-server');

// The GraphQL schema
const typeDefs = gql`
  type Query {
    "A simple type for getting started!"
    hello: String
  }
`;

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

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

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

Due to its human-readability, we recommend using schema-definition language (SDL) to define a GraphQL schema--a GraphQLSchema object from graphql-js can also be specified instead of typeDefs and resolvers using the schema property:

const server = new ApolloServer({
  schema: ...
});

Finally, start the server using node index.js and go to the URL returned on the console.

For more details, check out the Apollo Server Getting Started guide and the fullstack tutorial.

For questions, the Apollo community forum is a great place to get help.

Installation: Integrations

While the standalone installation above can be used without making a decision about which web framework to use, the Apollo Server integration packages are paired with specific web frameworks (e.g. Express, Koa, hapi).

The following web frameworks have Apollo Server integrations, and each of these linked integrations has its own installation instructions and examples on its package README.md:

Context

A request context is available for each request. When context is defined as a function, it will be called on each request and will receive an object containing a req property, which represents the request itself.

By returning an object from the context function, it will be available as the third positional parameter of the resolvers:

new ApolloServer({
  typeDefs,
  resolvers: {
    Query: {
      books: (parent, args, context, info) => {
        console.log(context.myProperty); // Will be `true`!
        return books;
      },
    }
  },
  context: async ({ req }) => {
    return {
      myProperty: true
    };
  },
})

Documentation

The Apollo Server documentation contains additional details on how to get started with GraphQL and Apollo Server.

The raw Markdown source of the documentation is available within the docs/ directory of this monorepo--to contribute, please use the Edit on GitHub buttons at the bottom of each page.

Development

If you wish to develop or contribute to Apollo Server, we suggest the following:

  • Fork this repository

  • Install Direnv (a tool that automatically sets up environment variables in project directories) or nvm. We use nvm to ensure we're running the expected version of Node (and we use Direnv to install and run nvm automatically).

  • Install the Apollo Server project on your computer

git clone https://github.com/[your-user]/apollo-server
cd apollo-server
direnv allow  # sets up nvm for you; if you installed nvm yourself, try `nvm install` instead
  • Build and test
npm install
npm test
  • To run individual test files, run npm run pretest && npx jest packages/apollo-server-foo/src/__tests__/bar.test.ts. Note that you do need to re-compile TypeScript before each time you run a test, or changes across packages may not be picked up. Instead of running npm run pretest from scratch before each test run, you can also run tsc --build tsconfig.json --watch in another shell, or use the VSCode Run Build Task to run that for you.

Community

Are you stuck? Want to contribute? Come visit us in the Apollo community forum!

Maintainers

Who is Apollo?

Apollo builds open-source software and a graph platform to unify GraphQL across your apps and services. We help you ship faster with:

  • Apollo Studio – A free, end-to-end platform for managing your GraphQL lifecycle. Track your GraphQL schemas in a hosted registry to create a source of truth for everything in your graph. Studio provides an IDE (Apollo Explorer) so you can explore data, collaborate on queries, observe usage, and safely make schema changes.
  • Apollo Federation – The industry-standard open architecture for building a distributed graph. Use Apollo’s gateway to compose a unified graph from multiple subgraphs, determine a query plan, and route requests across your services.
  • Apollo Client – The most popular GraphQL client for the web. Apollo also builds and maintains Apollo iOS and Apollo Android.
  • Apollo Server – A production-ready JavaScript GraphQL server that connects to any microservice, API, or database. Compatible with all popular JavaScript frameworks and deployable in serverless environments.

Learn how to build with Apollo

Check out the Odyssey learning platform, the perfect place to start your GraphQL journey with videos and interactive code challenges. Join the Apollo Community to interact with and get technical help from the GraphQL community.