How to: Integration test GraphQL

28 February, 2019

Author: Max Rozen

How to: Integration test GraphQL

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

What if a service could do it for you?

Instead of having to write the helper function, with OnlineOrNot all you need to do is copy your GraphQL query into a form.

At that point, the service will run the query every minute, and report back to you the instant anything goes wrong.

If that sounds like the kind of thing you'd like to try out, check out the Docs

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