Skip to main content
hitspec has first-class support for GraphQL. Instead of manually constructing JSON bodies, you write queries in a >>>graphql block and variables in a >>>variables block. hitspec handles the rest.

Prerequisites

The Complete Test File

This example tests the Countries GraphQL API, a free public GraphQL endpoint. Create a file called graphql.http:
graphql.http

Step-by-Step Breakdown

1

Write a GraphQL query with variables

The >>>graphql block contains the query, and >>>variables provides the variable values as JSON.
hitspec converts this into the standard GraphQL JSON format:
You write the query naturally and hitspec handles the serialization.
2

Assert nested response fields

GraphQL responses have a data wrapper. Use dot notation to reach nested fields.
The JSON path syntax supports:
  • Dot notation: body.data.country.name
  • Array indexing: body.data.country.languages[0].name
  • Length via gjson: body.data.country.languages.#
3

Capture values from GraphQL responses

Captures work the same way as with REST responses. Extract values for use in later requests.
These values are accessible as {{getCountry.countryName}} and {{getCountry.continentName}} in subsequent requests.
4

Query without variables

For queries with no variables, you can omit the >>>variables block.
5

Use the each operator for collections

The each operator applies an assertion to every element in an array.
This verifies that every item in the countries array is a JSON object.
6

Run the GraphQL tests

Run only smoke-tagged queries:
Expected output:

GraphQL Error Handling

GraphQL APIs return errors in a data.errors array. You can assert on these:
GraphQL APIs typically return HTTP 200 even for query errors. Always check body.errors in addition to the status code.

Next Steps

Multipart and GraphQL

Full reference for GraphQL blocks and multipart uploads.

Assertions

All 26 assertion operators available in hitspec.
Last modified on February 10, 2026