Testing GraphQL

Jake Dawkins

Who Am I

  • Apollo Architect
  • Best practices
  • Schema design & Testing

What I'm Talking About

  • The Purpose of Testing
  • Effectiveness of Tests
  • Testing Clients
  • Testing Servers

The Purpose of Testing

The Purpose of Testing

  • Safety of production code
  • Documentation

Effectiveness of tests

Testing Clients

Static Typing

  • Component props
  • Types based off production schema
  • apollo-cli

Unit Testing

  • "Making sure all the pieces are there"
  • Translation of props to rendered UI
  • react-testing-library

Integration testing

  • "Making sure the pieces fit together"
  • Loading, error, and expected states
  • Local state changes (cache updates)
  • MockedProvider

E2E Testing

  • "Making sure the app is usable"
  • Authentication headers passed to servers
  • Components are visible and accessible
  • cypress.io

Demo

Testing Servers

Static Typing

  • Type generation is not as easy as it sounds
  • Resolvers don't have to return anything
  • Default resolvers make this even harder

Unit Testing

  • Leverage GraphQL's dependency injection
  • DataSources are just classes
  • Resolvers are just functions

Integration Testing

  • Testing execution of an operation
  • apollo-server-testing 🎉 🎉

E2E Testing

  • Checking HTTP semantics
  • Making sure a valid request produces a valid response
  • Can use real or staging services

Demo

Testing is essential, so it should also be easy and effective.

Thank You!