# 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" ]
