5 Implementing schema resolvers

 

This chapter covers

  • Using Node.js drivers for PostgreSQL and MongoDB
  • Using an interface to communicate with a GraphQL service
  • Making a GraphQL schema executable
  • Creating custom object types and handling errors

In the previous chapter, we designed the structure of the GraphQL API schema and came up with its full SDL text. In chapters 5-8, we are going to make that schema executable. We’ll use Node.js database drivers and the GraphQL.js implementation to expose the entities in the databases by using resolver functions.

5.1 Running the development environment

To let you focus on the GraphQL skills in this book’s project, I prepared a Git repository that contains all the non-GraphQL things that you need to follow up with the project. We will use this repository in chapters 5-10. It has the skeleton for both the API server (which we’re going to build in chapters 5-8) and the skeleton for the web server (which we’ll build in chapters 9 and 10). Clone that repo.

Listing 5.1 Command to clone the book’s repo
git clone https://az.dev/gia-repo graphql-in-action

5.1.1 Node.js packages

5.1.2 Environment variables

5.2 Setting up the GraphQL runtime

5.2.1 Creating the schema object

5.2.2 Creating resolver functions

5.2.3 Executing requests

5.3 Communicating over HTTP

5.4 Building a schema using constructor objects

5.4.1 The Query type

5.4.2 Field arguments

5.4.3 Custom object types

5.4.4 Custom errors

5.5 Generating SDL text from object-based schemas

5.5.1 The schema language versus the object-based method

5.6 Working with asynchronous functions

Summary