Arrange Act Assert

Jag Reehals thinking on things, mostly product development

Introducing Code-First GraphQL APIs at Cambridge University Press

22 Feb 2021

Having experienced the pain of schema-first GraphQL projects, I wanted to use a different approach for a project I led at Cambridge University Press.

In this post, I'll describe what I used and how using code-first GraphQL worked out for us.

In my experience, having a single source of truth makes applications easier to understand, maintain and add features to.

A common approach when learning GraphQL is to adopt a schema-first approach. The difficulty and complexity of schema-first GraphQL APIs increases as the project and teams grow, as you have to ensure definitions and resolvers are in sync and have to maintain multiple sources of truth.

Code-first approach with Nexus

By using a code-first approach with Nexus, we were able to can have have a single source of truth as it will generate a GraphQL schema for you.

However Nexus does a lot more than saving from mistakes and time of generating a GraphQL scheme manually.

Thanks to excellent typescript integration Nexus provides a delightful developer experience with lightning-fast feedback.

The plugin system and extensibility points enabled us to create a GraphQL API that was easy to maintain and extend.

How how did Nexus and code-first GraphQL work out for us?

Having avoided the pitfalls of schema-first, the benefits of a code-first approach to building GraphQL APIs increased our productivity and enabled us to release features quickly knowing everything was in sync.

Over the next few months, I'll post examples of how we used Nexus and share what we learned when creating GraphQL APIs.

graphql