DEV Community

Cover image for Basic differences between three GraphQL-servers.
Pablo Yeverino
Pablo Yeverino

Posted on • Updated on

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

Top comments (6)

Collapse
 
themarcelolewin profile image
Marcelo Lewin

For yoga, the typeDefs allows you to pass an array or a file location. How can I pass an array with multiple file locations to break the schema apart. Or is that even possible?

Collapse
 
mittalyashu profile image
Yashu Mittal

There's also schema merging, in addition to stitching and each one of them has its own use-case.

Here's are reference links to their docs:

Collapse
 
pabloyeverino profile image
Pablo Yeverino

Hi! Thanks for reading.

I think that what you are looking for is "schema stitching".

Here is an excellent article from Prisma. It explains the use of graphql-import. Hope it works for you.

Please let me know!!

prisma.io/blog/graphql-schema-stit...

Collapse
 
themarcelolewin profile image
Marcelo Lewin

Thank you! I'll check that out. Also, would you be interested in being on my GraphQL { Resolvers } podcast? I'm about to launch it and would love to have on as a guest to chat GraphQL. if so, I can DM you my email address to continue our chat!

Collapse
 
sneknotsnake profile image
SnekNOTSnake

How about apollo-server-express? It's the most popular GraphQL server of all!
npmtrends.

Rawr!!

Collapse
 
pabloyeverino profile image
Pablo Yeverino

I'll take a look and update the post! Thanks man!! I haven't work on GraphQL lately