GraphQL

Protocols

Send GraphQL queries and mutations with variables and assert on the JSON data — a thin, ergonomic layer over the HTTP engine.

Browse all 52 demos 12 categories
Run it
$ loadr run examples/11-graphql.yaml
examples/11-graphql.yaml
# GraphQL over HTTP with variables; GraphQL `errors` are detected and the
# request is marked failed when no data comes back.
name: graphql
description: GraphQL queries with variables

defaults:
  http:
    base_url: https://api.example.com
    headers:
      Authorization: Bearer ${env.GRAPHQL_TOKEN}

scenarios:
  product_search:
    executor: ramping-vus
    start_vus: 0
    stages: [ { duration: 30s, target: 20 }, { duration: 3m, target: 20 } ]
    flow:
      - request:
          name: search products
          url: /graphql
          protocol: graphql
          graphql:
            query: |
              query Search($term: String!, $first: Int!) {
                products(search: $term, first: $first) {
                  edges { node { id name price } }
                  totalCount
                }
              }
            variables:
              term: "widget"
              first: 20
            operation_name: Search
          extract:
            - { type: jsonpath, name: first_id, expression: "$.data.products.edges[0].node.id" }
          checks:
            - { type: jsonpath, name: has results, expression: "$.data.products.totalCount" }
      - request:
          name: product detail
          url: /graphql
          protocol: graphql
          graphql:
            query: "query One($id: ID!) { product(id: $id) { id name description } }"
            variables: { id: "${first_id}" }

thresholds:
  graphql_req_duration: [ "p(95)<400" ]

View raw: examples/11-graphql.yaml

What it shows

  • Query + mutation with variables
  • Assert on data / errors
  • Reuse HTTP auth + cookies