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

# GraphQL Actions

> Call a provider's GraphQL API from a connector using the request step function.

For GraphQL APIs, use the `request` step function with `method: post` and the query in the body. Pass the query and its variables as separate `body` args.

```yaml theme={null}
steps:
  - stepId: graphql_query
    stepFunction:
      functionName: request
      parameters:
        url: /graphql
        method: post
        args:
          - name: query
            value: |
              query ListUsers($first: Int, $after: String) {
                users(first: $first, after: $after) {
                  nodes {
                    id
                    name
                    email
                  }
                  pageInfo {
                    hasNextPage
                    endCursor
                  }
                }
              }
            in: body
          - name: variables
            value:
              first: '{{$.inputs.page_size ?? 50}}'
              after: '{{$.inputs.cursor ?? null}}'
            in: body
```

## Error handling

GraphQL returns `200` even for errors, so check the response's `errors` field rather than the status code:

```yaml theme={null}
- stepId: check_errors
  condition: '{{present(steps.graphql_query.output.data.errors)}}'
  stepFunction:
    # Handle the error case.
```

## Best practices

* Define variables for every dynamic value, and pass them in a separate `variables` object rather than inlining them in the query string.
* Request only the fields you need, and use fragments for reusable field selections.
* For pagination, use the provider's cursor fields, such as `pageInfo.hasNextPage` and `pageInfo.endCursor`.

<Accordion title="Passing variables">
  Keep the query static and supply values through `variables`:

  ```yaml theme={null}
  args:
    - name: query
      value: 'query GetUser($id: ID!) { user(id: $id) { name } }'
      in: body
    - name: variables
      value:
        id: $.inputs.user_id
      in: body
  ```
</Accordion>

## Related

<CardGroup cols={2}>
  <Card title="Step functions: request" icon="cube" href="/connector-yaml-reference/step-functions/request">
    The request step used to issue the GraphQL POST.
  </Card>

  <Card title="Expression language" icon="brackets-curly" href="/connector-yaml-reference/expression-language">
    JEXL defaults and conditions used in the query variables and error check.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.