When building a GraphQL server, one of the first decisions you must make is which GraphQL implementation to use. There are three popular options.

  1. GraphQL.js — This is the reference implementation for GraphQL. GraphQL schemas are built by composing objects created from classes such as GraphQLObjectTypeGraphQLInterfaceType, and GraphQLEnumType.
  2. TypeGraphQL — This implementation builds upon the reference implementation and adds built-in TypeScript support. It makes it easier to make schemas typesafe. GraphQL schemas are built by creating classes and decorating them and their methods with TypeGraphQL decorators.
  3. GraphQL Nexus — Similarly to TypeGraphQL, this implementation builds upon the reference implementation and adds built-in TypeScript support. However, the approach taken is much different. Similarly to the reference implementation, GraphQL schemas are created by composing objects created from classes such as objectTypeinterfaceType, and enumType. Unlike the reference implementation, Nexus uses some black magic TypeScript trickery so that your schemas are more strongly typed. Unfortunately, as we’ll see below, this doesn’t always work so well.

In order to do a proper comparison of these three implementations, I’ll show how you can build the  Star Wars schema using each of them and talk about their pros and cons. At the end, I’ll give my opinion on which one I prefer using.

The code shown in this article can be found here.

  • Star Wars schema implemented using GraphQL.js.
  • Star Wars schema implemented using TypeGraphQL.
  • Star Wars schema implemented using GraphQL Nexus.
  • Star Wars schema implemented using GraphQL.js + GraphQL Code Generator.

#typegraphql #graphql #graphql-nexus #javascript

GraphQL.js vs. TypeGraphQL vs. GraphQL Nexus
14.40 GEEK