> ## Documentation Index
> Fetch the complete documentation index at: https://momentic.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# graphqlRequest

> Make a server-side GraphQL request and capture the response.

GraphQL companion to `request`. `variables` accepts an object or a JSON-encoded
string.

## Parameters

| Parameter   | Type                     | Required | Description                                                           |
| ----------- | ------------------------ | -------- | --------------------------------------------------------------------- |
| `url`       | `string`                 | Yes      | GraphQL endpoint URL.                                                 |
| `query`     | `string`                 | Yes      | GraphQL document.                                                     |
| `variables` | `unknown`                | No       | GraphQL variables map.                                                |
| `headers`   | `Record<string, string>` | No       | Request headers.                                                      |
| `timeout`   | `number`                 | No       | Maximum time in milliseconds.                                         |
| `saveAs`    | `string`                 | No       | Name of the variable to write this step's return value to.            |
| `retries`   | `number`                 | No       | Number of times to retry the step on failure before failing the test. |
| `skipped`   | `boolean`                | No       | Skip this step at execution time.                                     |

## Examples

```yaml theme={null}
- graphqlRequest:
    url: https://rickandmortyapi.com/graphql
    query: |-
      query Query {
        characters(page: 2, filter: { name: "Morty" }) {
          info {
            count
          }
          results {
            name
          }
        }
        location(id: 1) {
          id
        }
      }
    saveAs: CHARACTERS
```

```yaml theme={null}
- graphqlRequest:
    url: https://rickandmortyapi.com/graphql
    query: "query User($id: ID!) { user(id: $id) { name } }"
    variables:
      id: user-1
    headers:
      x-trace-id: "{{ env.TRACE_ID }}"
    saveAs: USER
```

## Related

* [Network requests](/guides/page-interactions/network-requests)
* [Test format](/core-concepts/test-format)
