Skip to content

Guide · Open source

How to use apollo-server: install and run a GraphQL API

Updated · written with AI from the project's own documentation and checked against our catalogue data

apollo-server is an open-source JavaScript library for running a GraphQL API on Node.js. You describe your data with a GraphQL schema, write resolver functions that fetch the data for each field, and expose the result over HTTP. This guide is for developers who already know some Node.js and want to add a GraphQL endpoint to an app. By the end you will know what to install, how the pieces fit together and when this library is the wrong choice.

Apollo Serverapollographql/apollo-server · ★ 14k · MIT

Quick start

  1. 1Install Node.js. Make sure Node.js is installed on your machine, since apollo-server runs only on Node.js.
  2. 2Install the packages. Run npm install @apollo/server graphql in your project folder.
  3. 3Write your schema. Describe the types and fields your API exposes in a GraphQL schema.
  4. 4Implement resolvers. Write a resolver function for each field that returns data.
  5. 5Connect to your framework. Plug the server into Express, Koa, Hapi or another supported Node framework using the official documentation.
  6. 6Send a test query. Send a GraphQL query over HTTP to the endpoint and confirm the returned data matches your resolvers.

What apollo-server does and who it is for

Apollo Server is a library, not a hosted service. You run it inside your own Node.js project. It plugs into common Node web frameworks, so clients can send GraphQL queries over HTTP to the endpoint your app provides. The project describes itself as spec-compliant and production ready, and as built for a schema-first way of working.

It fits best if you want to add a GraphQL API to an existing Express, Koa or Hapi app, or if your team prefers to define the schema first and then implement resolvers. It is not a good fit if you only need a REST API or a static site, or if your project must use a non-Node.js server language.

  • Licence: MIT
  • Language: TypeScript
  • Runs on: Node.js
  • Frameworks named in the project description: Express, Connect, Hapi, Koa, and more

Install apollo-server on Node.js

You need Node.js installed. The project's README gives the package-manager install command below, which installs the server package along with graphql.

npm install @apollo/server graphql

Define a schema and resolvers

A GraphQL schema describes the types and fields your API exposes. Resolvers are functions that return the data for each field. In a schema-first workflow you write the schema, then implement the resolvers that match it.

Keep the schema as the contract between your front end and back end. Each field a client can request should have a resolver that returns its value, whether that data comes from a database, another service or memory.

  • Write the schema describing your types and queries.
  • Write a resolver function for each field that needs to return data.
  • Pass the schema and resolvers to the server when you create it.

Connect the server to an HTTP framework

apollo-server is designed to plug into Node web frameworks such as Express, Koa and Hapi. Once connected, clients send GraphQL queries to the HTTP route your framework serves. Check the project's documentation at https://www.apollographql.com/docs/apollo-server/ for the integration code for your chosen framework, since the README excerpt used for this guide does not include it.

Common mistakes and troubleshooting

Most early problems come from setup rather than the library itself. If the install fails, confirm that Node.js is installed and that you ran the install command inside your project folder. If queries return nothing, check that every field a client requests has a matching resolver in your schema.

Remember that apollo-server runs only on Node.js. If you try to use it from a different server language, it will not work for that part of the stack.

  • Install failed: confirm Node.js is present and run npm from the project folder.
  • Field returns null or nothing: check that a resolver exists for that field.
  • Wrong runtime: the library runs only on Node.js.

What people use it for

  • Adding a GraphQL endpoint to an existing Express app
  • Building a schema-first API where front-end and back-end teams agree on types early
  • Serving data from a database or other services through one GraphQL layer
  • Creating a TypeScript-based GraphQL server for a Node.js project

Frequently asked questions

Is apollo-server free to use?

apollo-server is released under the MIT licence, which is a permissive open-source licence. Check the licence file in the repository for the full terms before you use it commercially.

What do I need to run apollo-server?

You need Node.js. The library is installed with npm using the command npm install @apollo/server graphql. It runs only on Node.js.

Which frameworks does apollo-server work with?

The project says it is built for Express, Connect, Hapi, Koa, and more. Use the official documentation to find the integration for your framework.

What are alternatives to apollo-server?

Comparable projects include graphql-yoga, express-graphql, Mercurius and graphql-helix. Compare them on the framework you use, the schema approach and the documentation before choosing.

Can I use apollo-server if I only need a REST API?

No, not in a useful way. The project is for GraphQL, and GraphQL adds a layer that a REST-only project would not use. A plain REST framework is a better fit.

Does apollo-server work without JavaScript or TypeScript?

No. You write the server code in JavaScript or TypeScript, and the library runs only on Node.js. Projects that need another server language should look elsewhere.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

apollo-server suits Node.js developers who want an MIT-licensed, TypeScript GraphQL server that plugs into Express, Koa or Hapi and follows a schema-first approach. If you only need REST, a static site, or a non-Node.js backend, pick a different tool. Compare it with the listed alternatives if your framework or workflow differs.

Install options & downloads