apollo-server vs express-graphql vs graphql-http vs graphql-yoga
GraphQL Server Libraries
apollo-serverexpress-graphqlgraphql-httpgraphql-yogaSimilar Packages:

GraphQL Server Libraries

GraphQL server libraries are tools that facilitate the implementation of GraphQL APIs, allowing developers to define schemas, handle queries and mutations, and manage data fetching efficiently. These libraries provide various features that cater to different use cases, from simple setups to more complex, production-ready applications. They help streamline the development process by providing built-in functionalities like middleware support, subscriptions, and easy integration with existing frameworks, ultimately improving developer productivity and API performance.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
apollo-server013,93726.6 kB822 years agoMIT
express-graphql06,280-555 years agoMIT
graphql-http0364406 kB6a year agoMIT
graphql-yoga08,511298 kB13811 days agoMIT

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

Ease of Use

  • apollo-server:

    Apollo Server is designed to be user-friendly, with a straightforward setup process. It provides extensive documentation and a rich set of features that make it easy to implement complex GraphQL schemas and resolvers without much boilerplate code.

  • express-graphql:

    Express-GraphQL is simple to integrate into existing Express applications. It requires minimal configuration and allows developers to quickly expose a GraphQL endpoint, making it an excellent choice for those already familiar with Express.

  • graphql-http:

    GraphQL HTTP is extremely lightweight and easy to set up. It provides a simple way to create a GraphQL endpoint with minimal configuration, making it ideal for quick implementations or learning purposes.

  • graphql-yoga:

    GraphQL Yoga offers a developer-friendly experience with sensible defaults and built-in features. It simplifies the setup process and provides a great starting point for new projects, making it accessible for beginners.

Integration

  • apollo-server:

    Apollo Server integrates seamlessly with various data sources, including REST APIs, databases, and other GraphQL services. It also works well with Apollo Client, allowing for a cohesive development experience across the stack.

  • express-graphql:

    Express-GraphQL is designed to work within the Express ecosystem, allowing developers to leverage existing middleware and routing capabilities. This makes it easy to integrate GraphQL into applications that already use Express.

  • graphql-http:

    GraphQL HTTP is designed to be framework-agnostic, allowing it to be used with any HTTP server. This flexibility makes it easy to integrate into various environments, although it may require additional setup for more complex use cases.

  • graphql-yoga:

    GraphQL Yoga is built on top of Express and integrates well with various tools and libraries in the Node.js ecosystem. It provides built-in support for features like subscriptions and file uploads, making it a versatile choice.

Performance

  • apollo-server:

    Apollo Server is optimized for performance, offering features like query batching and caching out of the box. It also provides tools for monitoring and optimizing performance in production environments, ensuring efficient data fetching.

  • express-graphql:

    Express-GraphQL is lightweight and performs well for most use cases. However, it may require additional optimization for high-traffic applications, as it does not include built-in performance enhancements like caching.

  • graphql-http:

    GraphQL HTTP is minimalistic and performs efficiently for simple use cases. However, for more complex applications, developers may need to implement their own performance optimizations.

  • graphql-yoga:

    GraphQL Yoga is designed for performance with features like automatic persisted queries and subscriptions. It aims to provide a balance between ease of use and performance, making it suitable for a wide range of applications.

Community and Ecosystem

  • apollo-server:

    Apollo Server has a large and active community, with extensive resources, plugins, and integrations available. This ecosystem provides support for various tools and libraries, making it a popular choice for developers.

  • express-graphql:

    Express-GraphQL benefits from the large Express community, providing access to a wealth of middleware and resources. However, its ecosystem is more limited compared to Apollo Server.

  • graphql-http:

    GraphQL HTTP is relatively new and has a smaller community. While it is straightforward to use, it may lack the extensive resources and support found in more established libraries.

  • graphql-yoga:

    GraphQL Yoga has a growing community and is part of the larger GraphQL ecosystem. It provides access to various tools and integrations, making it a solid choice for developers looking for a modern solution.

Flexibility

  • apollo-server:

    Apollo Server offers a high degree of flexibility, allowing developers to customize their GraphQL implementation extensively. It supports various data sources and integrations, making it adaptable to different project requirements.

  • express-graphql:

    Express-GraphQL provides flexibility in how you structure your GraphQL server within an Express application. However, it may require more manual configuration for advanced use cases compared to other libraries.

  • graphql-http:

    GraphQL HTTP is highly flexible due to its minimalistic design, allowing developers to build their own custom solutions around it. However, this may require more effort for complex implementations.

  • graphql-yoga:

    GraphQL Yoga strikes a balance between flexibility and ease of use, providing sensible defaults while allowing customization for more advanced features. It is suitable for both quick prototypes and production-ready applications.

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

  • apollo-server:

    Choose Apollo Server if you need a comprehensive and feature-rich solution that supports advanced features like caching, subscriptions, and integration with Apollo Client. It is well-suited for building production-ready GraphQL APIs with a focus on performance and developer experience.

  • express-graphql:

    Choose Express-GraphQL if you are already using Express.js and want a lightweight solution to add GraphQL capabilities to your existing application. It is ideal for developers looking for simplicity and direct integration with Express middleware.

  • graphql-http:

    Choose GraphQL HTTP if you need a minimalistic and straightforward solution for serving GraphQL over HTTP. It is suitable for simple use cases or when you want to quickly set up a GraphQL endpoint without additional features or dependencies.

  • graphql-yoga:

    Choose GraphQL Yoga if you want an easy-to-use and flexible GraphQL server that comes with sensible defaults and built-in features like subscriptions and file uploads. It is great for rapid prototyping and development, especially for those new to GraphQL.

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.