How to test GraphQL for correctness on Hasura using OnlineOrNot

19 January, 2019

Author: Max Rozen

How to test GraphQL for correctness on Hasura using OnlineOrNot

What is Hasura

When I say Hasura, I mean the Hasura GraphQL engine, which they describe as a way to "setup a GraphQL server and event triggers over a Postgres database in minutes".

Getting started with Hasura

To quickly get set up using Hasura I followed this guide - it quickly sets up a User table, so you can get querying, like so: Hasura Setup

Once that's working I then secured my endpoint following this guide - you can never be too careful!

Testing in OnlineOrNot

  1. To start testing on OnlineOrNot, we'll need to define a new Application, as follows: OnlineOrNot Application Setup
  2. Once the Application is defined, we're ready to create a new Test. To do this I copied the query, variables and header information I needed out of Hasura. Take special note to add "X-Hasura-Access-Key" to the Headers field if you secured your endpoint. Once the Application, Query, Variables and Headers fields are filled out you can click the "Test" button to retrieve an Expected Result from Hasura. OnlineOrNot Test Setup After you've filled out the relevant fields, hit Submit and wait a few minutes for OnlineOrNot to begin testing.
  3. After a minute, OnlineOrNot will start regularly testing the Hasura endpoint to ensure the returned value matches your initial setup value: OnlineOrNot Test Results
  4. After a few more minutes, the performance dashboard at the Home screen will start showing data: OnlineOrNot Latency Results


If we wanted to take this one step further and add Slack notifications for every time the GraphQL query takes too long to respond, or responds with unexpected data (because someone on your team edited a record, or changed the value a resolver returns), we can!

  1. In OnlineOrNot, we go back to the Applications view, and click on our Hasura Application: OnlineOrNot Applications List
  2. On this screen we can add a Slack integration: OnlineOrNot Slack Integration
  3. If we wanted to modify which events to send notifications for, we go back to the Tests view, click on our Hasura test, and uncheck the notifications you no longer wish to receive: OnlineOrNot Test Notifications


If you've made it this far, you've managed to fully automate GraphQL testing against your server, with downtime notifications! Congrats!

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