GraphQL for Beginners: Schema-first vs Code-first

Victoria Lo
4 min readAug 17, 2022

Let’s take a look at the 2 ways we can build a GraphQL API. How they are different and their pros and cons.

GraphQL has become a revolutionary scheme in the API world. As a solution to data fetching more efficiently, the first question you will need to ask yourself when building a GraphQL API is: schema-first or code-first?

In this article, let’s take a look at the 2 different approaches to implementing a GraphQL API and discuss when is best to use them.

This post is inspired by Dhruva Srinivas, who asked a question around this topic. Shoutout to him!

Note: If you need a refresher on GraphQL APIs, feel free to read my Introduction to GraphQL article.

There has been a lot of debate about which type of implementation is better. When GraphQL was first launched in 2016, only the schema-first approach exists. Therefore, developers who adopted GraphQL early might be more familiar with this approach.

The schema-first approach focuses on the designing and defining the GraphQL Schema first, then adding the resolver functions. From my GraphQL for Beginners article, recall that a schema is the blueprint of a GraphQL API.

It looks something like this:

type User {
_id: ID!
username: String
name: String
tagline: String
dateJoined: String
numFollowing: Int
numFollowers: Int

It defines the data types and relationships of these data that makes up the API. To define a schema, you need to know the Schema Definition Language (SDL). Hence, the schema-first is sometimes called the SDL-first approach too.

Here’s a brief look at how SDL defines the schema of a GraphQL API.

In a development work environment, the SDL way is readable for both technical and nontechnical team members. Once the API design is complete and the schema is finalized, both front and back-end teams can work on…

Victoria Lo

A nerd in books, tea and programming. I publish weekly on my personal blog: