Max Rozen

How to: Integration test GraphQL

February 28, 2019 • ☕️ 1 min read

What does Integration Testing even mean for GraphQL?

Integration testing in the context of GraphQL means testing your server’s ability to call the resolvers to fetch the data.

Typically you’d already have individual unit tests for the logic within your resolvers, and you just want to test whether or not your server actually sends the data the way you expect it to.

How do you do it?

First off, you’re going to need a GraphQL server.

You’ll then need to write a helper function that runs GraphQL queries against your server’s address.

First run

For each test, the function will need to:

  • Run the GraphQL query against the server
  • Save the result as a snapshot, preferably to JSON, as well as any desired metrics such as latency

Subsequent runs

For each test on subsequent runs, the function will need to:

  • Run the GraphQL query against the server
  • Record the result of the query, as well as some metrics
  • Compare the result of the query to the saved snapshot, noting down any differing or missing values

Discuss on TwitterEdit on GitHub

Enjoyed this post? Receive the next one in your inbox!

I won't send you spam.

Unsubscribe at any time.

MaxRozen.com

Max Rozen

Thoughts on business, software, and marketing by Max Rozen [About]