Nathan Wesley
Nathan Wesley

Reputation: 59

How to dynamically load GraphQL Queries from different files into JMeter for load testing?

My team needs to add load testing for our GraphQL API, and we decided to use JMeter because it is supported by Azure Load Testing.

We have several graphql files that define queries like this:

request.graphql

query Foo($id: Long!) {
  name
  time
}

With corresponding test.json files used for unit testing that defines the query name, variables for the request, and an assert that contains the expected response from our API

request.test.json

[
  {
    "Query": "Foo",
    "Variables": {
      "id": 001
    },
    "Assert": {
      "name": "bar",
      "time": "01/01/1999"
    }
  }
]

We have dozens of these unit tests that we want to use for load testing our API using JMeter. How would we dynamically load our queries, variables, and assertions using JMeter, and load that into Azure Load Testing?

This is currently my very basic test plan with one graphql HTTP request. I want to avoid manually adding every single query, so that the queries in load tests get updated when a graphql and test.json file gets changed for our API.

enter image description here

Upvotes: 0

Views: 116

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

Take a look at:

  1. Directory Listing Config plugin (can be installed using JMeter Plugins Manager)
  2. __FileToString() function

The idea is to point the Directory Listing Config to the folder where your files containing GraphQL queries live. It will pick up the next file on each iteration of each virtual user and return the path to the file.

enter image description here

Then you can read the content of your file using the aforementioned __FileToString() function directly in the sampler's body:

enter image description here

Upvotes: 0

Related Questions