Using GraphQL in API Monitoring

You can integrate GraphQL queries into your tests, expanding your ability to handle modern API architecture.

Getting Started with GraphQL Testing

To create and run tests using GraphQL, follow these steps:

  1. Create or edit an API Monitoring test.

  2. In Steps, add an API request. Set Request Type to POST and provide the Endpoint URL.

  3. In Parameters, select Add GraphQL Body.

  4. Input Your GraphQL body in the Query box.

    Click the Auto Fetch button to retrieve the latest API schema. The rich text editor enhances readability with syntax highlighting, real-time auto-complete, and error validation.

  5. Once the query is in place, click Run Now or Save & Run to validate the response.

Importing GraphQL Queries from Postman

API Monitoring supports migration of GraphQL queries from Postman. You can import individual GraphQL queries from a Postman collection file, or do a bulk import of multiple collection files using a ZIP file.

To import GraphQL queries:

  1. In API Monitoring, select Create Test > Import Test.

  2. In Import Tests, select Postman Collection v2 / v1 / Data Dump and choose a file to upload. Supported format: JSON (for individual collection) or ZIP (for multiple JSON files).

  3. Click Import Requests and review the imported queries in the test editor.

Using Variables in GraphQL Tests

You can combine GraphQL with variables to make dynamic queries. Here’s an example of how to incorporate variables into your tests:

  1. Go back to the test you created earlier and click Edit Test.

  2. In the POST request, define your variables and values in the GraphQL Variables box. For example:

    {
    	"limit": 5
    }			

    You can also use API Monitoring Initial Variables as follows:

    1. Navigate to Environment > Test Settings > Initial Variables.

    2. Define the Name and Value for each initial variable. For example, the variable name is launches and the value is 2.

    3. Return to your POST request. You’ll find available variables listed in the right-hand frame under Parameterisation > Available Variables.

    4. In the GraphQL Variables box, replace a value with an initial variable either by hardcoding it directly, or by clicking on the variable name from the available variables list. For example:

      {
      	"limit": {{launches}}
      }
  3. Click Save & Run to validate the dynamic behavior of your query.

To see how GraphQL support works in API Monitoring, watch the following video: