Running Apollo Server

  • Node js
  • Npm
  • VS Code
  1. Create a new project. In my case it’s apollo-testing.
  2. Open the code in VS Code.
  3. Create a file name “index.js” inside the folder
  4. Open terminal in VS code and execute below commands. npm init -y converts your folder into Node js project with package.json file inside it. npm install apollo-server graphql installs apollo-server and graphql dependencies.
npm init -y
npm install apollo-server graphql
const { ApolloServer, gql } = require('apollo-server');
// A schema is a collection of type definitions (hence "typeDefs")
// that together define the "shape" of queries that are executed against
const typeDefs = gql`# This "Book" type defines the queryable fields for every book in our data source.type Book {
title: String
author: String
# The "Query" type is special: it lists all of the available queries that# clients can execute, along with the return type for each. In this# case, the "books" query returns an array of zero or more Books (defined above).type Query {books: [Book]}`;const books = [{title: 'The Awakening',author: 'Kate Chopin',},{title: 'City of Glass',author: 'Paul Auster',},];// Resolvers define the technique for fetching the types defined in the
// schema. This resolver retrieves books from the "books" array above.
const resolvers = {
Query: {
books: () => books,
// The ApolloServer constructor requires two parameters: your schema
// definition and your set of resolvers.
const server = new ApolloServer({ typeDefs, resolvers });// The `listen` method launches a web server.server.listen().then(({ url }) => {console.log(`🚀 Server ready at ${url}`);});
node index.js
🚀 Server ready at http://localhost:4000/




Learner. Observer. Interested in software development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

JWT User Authentication with Node.js & Express

C++ 11 Hash Table, Hash Map, Dictionaries, Set, Iterators

When to Use Context API vs Redux

Title of the article

More TypeScript Learning Resources

Getting documents from Firestore in Front end

Hosting your Angular Static Site to AWS S3 through Azure DevOps.

Migrating from WordPress to DADI Web

Adopting styled components with Typescript in React Native

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akanksha Pardeshi

Akanksha Pardeshi

Learner. Observer. Interested in software development.

More from Medium

PDKit: Project as Code

Apollo Federation v2 by example

How to Handle Objection.Js

Lessons learned integrating AppSignal APM with NestJS