# GraphQL

The `Graphql` class is a utility for interacting with GraphQL APIs. It provides a single static function to send queries or mutations to a GraphQL endpoint and retrieve the results.

Since the method is **static**, you do not need to create an instance of this class.

***

### request

Sends a query or a mutation to a specified GraphQL API endpoint.

**Parameters**

* `url`: The endpoint URL of the GraphQL API.
* `document`: The GraphQL query or mutation, written in standard GraphQL syntax.
* `variables`: An optional object containing any variables required by the document.
* `headers`: An optional object for sending request headers, commonly used for authentication.

**Example: Simple Query** This example queries for a list of movies.

```yaml
# url
https://api.example.com/graphql
# document
query {
  movies {
    id
    title
    releaseYear
  }
}
```

**Example: Query with Variables** This example fetches a single movie by its ID, which is passed as a variable.

```yaml
# url
https://api.example.com/graphql
# document
query getMovieById($movieId: ID!) {
  movie(id: $movieId) {
    title
    director {
      name
    }
  }
}
# variables
movieId: "123"
```

**Example: Mutation** This example creates a new movie.

```yaml
# url
https://api.example.com/graphql
# document
mutation createMovie($title: String!, $year: Int!) {
  createMovie(title: $title, releaseYear: $year) {
    id
    title
  }
}
# variables
title: My New Movie
year: 2025
```

**Example: Query with Authentication** This example sends an `Authorization` header with a Bearer token.

```yaml
# url
https://api.example.com/graphql
# document
query {
  myPrivateData {
    secretInfo
  }
}
# headers
Authorization: Bearer my-secret-auth-token
```

**Output** The data payload returned by the GraphQL API in response to the query or mutation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.heisenware.com/app-builder/build-backend/function-explorer/connectors/graphql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
