Basic differences between three GraphQL-servers.

pabloyeverino

Pablo Yeverino

Posted on November 17, 2019

Basic differences between three GraphQL-servers.

Hello!!!

TL;DR: A comparison between express-graphql, apollo and yoga was made for a Hello World! Query. In order to setup a simple GraphQL API, considering the size and number of files, Express-graphql is the champion here🥇. The complexity of the SDL Implementation is not very different and definitely a more extensive analysis has to be done in order to choose a tool for an enterprise size application.

I wanted to compare express-graphql, apollo and graphql-yoga with Node.js The main information that I want to get are dependencies, size of development project and the most important, the way to implement the Schema definition language (SDL), in order to build the schema.

Express-graphql.

This is the simplest way to run a GraphQL API.

Dependencies:

  • graphql
  • express
  • express-graphql

Size:

  • 5.1 MB
  • 862 files.

SDL implementation.

The buildSchema method is imported from graphql in order to build the schema.



const { buildSchema } = require('graphql');

const schema = buildSchema(`
  type Query {
    hello: String!
  }
`);


Enter fullscreen mode Exit fullscreen mode

Here is the video of all the steps.

Video preview

Apollo Server.

At the Apollo Documentation we can read that Apollo Server is the best way to build a production-ready, self-documenting API for GraphQL API clients, using data from any source.

Dependencies:

  • graphql
  • apollo-server

Size:

  • 16.7 MB
  • 4,502 files.

SDL Implementation

  • The gql function is imported from apollo-server to parse the plain string that contains the GraphQL code.


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

const typeDefs = qgl`
  type Query {
    hello: String!
  }
`;


Enter fullscreen mode Exit fullscreen mode

Is worth to note a difference between the resolvers with Express and Apollo, in the former you only add the function which will resolve the hello Query. In the last, you have to define the resolvers according to the types.

Also I made a video implementing the Apollo server.

Video preview

GraphQL-Yoga Server

Graphql-yoga is a fully-featured GraphQL Server focused on easy setup, performance and great developer experience as can be read at the creator's repo. It was created by Prisma.

Dependencies:

  • graphql-yoga

Size:

  • 14.6 MB
  • 4,634 files.

SDL Implementation

  • In this case, any function has to be imported in order to parse the plain string, so the schema is created out of it completely.



const typeDefs = `
  type Query {
    hello(name: String): String!
  }
`;


Enter fullscreen mode Exit fullscreen mode

The resolvers have to be defined in the same way as with Apollo, by type and field.

Here is the video of the same API that have been created in the other two cases. In this example, the query can take an String argument.

Video preview

💖 💪 🙅 🚩
pabloyeverino
Pablo Yeverino

Posted on November 17, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related