Testing a GraphQL API — GraphQL · NestJS

Write the end-to-end tests of the cats schema: a fresh application per test, queries and mutations posted to /graphql with supertest, answers compared as data and errors as codes, until four bugs planted in the code are all caught.

What you will learn

Read the theory for Testing a GraphQL API

All GraphQL lessons

All NestJS courses

loading types…

What you'll learn

  • Boot the GraphQL application in a test with @nestjs/testing, a fresh one per test so that mutations cannot leak between tests
  • Send queries and mutations as POST /graphql with supertest, variables included
  • Assert on data, and on errors by their extensions.code, knowing that the HTTP status is 200 either way
  • Check a mutation by its effect, querying afterwards, not only by what it answers