Why our team chose Prisma2 & nexus/schema for GraphQL Apollo Server

Clark Song
dooboolab
Published in
4 min readJun 19, 2020

My team, dooboolab, and I were bulding graphql-server with Apollo-Server and Sequelize as ORM tool. But, recently, we’ve decided to replace Sequelize with Prisma2 for several reasons.

Prisma2

We knew Sequelize or TypeORM is much more popular in the market.
For example, it seems that Sequelize and TypeORM are ahead of Prisma in ‘npm trends’ page.

npm trends graph between prisma2, sequelize, and typeorm

However, Prisma in the graph means Prisma2, which was just released in early 2019 and still beta version(except Prisma Client). So, it is easy to know that the graph above is actually not a good comparison.

Anyhow, the main reason for choosing Prisma2 over Sequelize was its major features and potential for growth. Even though Sequeize launched its v.5 on March 13, 2019, it still lacks major features. Let me tell you three main points. First, we needed to write a migration script manually with Sequelize. Even if some function like ‘sequelize.sync’ exists for this reason(Here is a post about sequelilze.sync), it can’t be used in the production environment. Some other libraries for this such as sequelize-auto-migrations are outdated and cannot be used with Sequelize v.5. The second reason is that the support for typescript is still not good enough. To create a service with TypeScript and Sequelize, we had to find many workarounds that are not even on the document. (You can see our code built on Sequelize v.5 & TypeScript here). Last but not least, its poor and complex documentation is not just bad but made me doubt whether Sequelize is managed by a good team or not.

On the other hand, these three issues are all solved by Prisma2. Prisma Migrate makes a migration script with the simple command prisma migrate up -—experimental. When it comes to compatibility with Typesciprt, Prisma2 was built to enable Type-safe database queries in the beginning. So far, we haven’t faced any critical issue using Typescript. Moreover, Prisma’s documentation is neat and clean. Some parts of it need to be added though, most of the content is written with a brief explanation and correct information. You can visit Prisma2 documentation here.

Apart from these three things, Prisma2 has advantage over Sequelize for its innate functions like ‘introspection’, ‘studio’, etc.

nexus/schema

We also introduced nexus/schema in setting up the graphql-server. Because nexus/schema creates GraphQL SDL(Schema Definition Language) and GraphQL types on behalf of us.

With Prisma1 or Sequelize, however, we had to define Graphql SDL(generally named as schema.graphql) as below on our own.

Graphql SDL

Graphql SDL of Model type

And also GraphQL SDL for Query, Mutation, and Subscription types has to be defined.

GraphQL SDL of Query, Mutation, and Subscription types

It seems that writing SDL is not a big deal at first glance. But, if this schema increases to hundreds and thousands of types, it will become very tedious and inefficient work.

nexus/schema

nexus’s schema component

With nexus/schema, we can define schema using nexus’s schema component. nexus/schema makes GraphQL SDL for not only models but also queries, mutations, and subscriptions according to the nexus’s schema component and resolvers. Therefore, we don’t need to define SDL such as Query, Mutation, and Subscription types and only care nexus’s schema component of models. In addition, nexus’s schema component is more simple and easy to write than GraphQL SDL.

This is the result of the auto-generated GraphQL SDL.

schema.graphql generated by nexus/schema

You can also see the auto-generated GraphQL types.

GraphQL types

I will continue this topic in the next post with the actual boilerplate code of GraphQL server with Prisma2 & nexus/schema.

Thanks for reading!

Difference between ‘nexus’ and ‘nexus/schema’ ?

nexus is slightly different from nexus/schema in that it gives many functions and covers more part of graphql-server development— Auto-generation of GraphQL SDL, graphql-server included by default, pursuit of zero config, Bundled CLI, Batteries included, etc.
Meanwhile, nexus/schema only focus on auto-generation of GraphQL SDL.
So to speak, nexus is code-first library and nexus/schema is the mix of schema-first and definition first development.

nexus link : https://www.nexusjs.org/#/README
nexus/schema link : https://www.nexusjs.org/#/components/schema/about

--

--