> For the complete documentation index, see [llms.txt](https://v2.dataos.info/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://v2.dataos.info/references/interfaces/apis/data-product-apis/querying-data-products/graphql.md).

# GraphQL

A typed API for selecting Data Product fields and receiving nested results.

GraphQL is useful when you want schema discovery, typed field selection, and a query shape that fits frontend clients. It targets the same semantic layer as REST and Semantic SQL.

**Endpoint:** `POST /api/v1/query/semantic/graphql`

**Headers:** `Authorization: Bearer $TOKEN`, `X-User: <user-id>`

## Response lifecycle

GraphQL returns rows in the same response when the query finishes within \~55 seconds (`200` with `data`). If it is still running, you get `202` with `Retry-After` and `extensions.statementId`. Retry the GraphQL request or poll the statement API in [Query lifecycle](https://v2.dataos.info/references/interfaces/apis/data-product-apis/querying-data-products/advanced/query-lifecycle.md).

| Outcome                        | HTTP                                                  | What you do                                                      |
| ------------------------------ | ----------------------------------------------------- | ---------------------------------------------------------------- |
| Query finishes in time         | `200` with `data`                                     | Use `data`. No polling.                                          |
| Query still running at timeout | `202` with `Retry-After` and `extensions.statementId` | Retry after the wait, or poll `GET /api/v1/query/statement/{id}` |
| Identical query retried        | `202` (may reuse result)                              | Same deduplication as async submits.                             |

For queries that routinely run longer than \~55 seconds, use [REST](https://v2.dataos.info/references/interfaces/apis/data-product-apis/querying-data-products/rest.md) or [Semantic SQL](https://v2.dataos.info/references/interfaces/apis/data-product-apis/querying-data-products/semantic-sql.md).

On timeout the response is `HTTP 202` with `Retry-After: 30` and a body like:

```json
{
  "data": null,
  "extensions": {
    "status": "IN_PROGRESS",
    "statementId": "a3f8c1d2-...",
    "_links": {
      "self": { "href": "/api/v1/query/statement/a3f8c1d2-..." },
      "result": { "href": "/api/v1/query/statement/a3f8c1d2-.../result" }
    }
  }
}
```

## Basic query

GraphQL:

```graphql
query {
  table(limit: 10) {
    orders {
      store_region
      total_units
    }
  }
}
```

REST equivalent:

```json
{
  "query": {
    "measures": ["orders.total_units"],
    "dimensions": ["orders.store_region"],
    "limit": 10
  }
}
```

## Time granularity

```graphql
query {
  table {
    orders {
      product_category
      total_revenue
      order_date {
        day
      }
    }
  }
}
```

REST equivalent:

```json
{
  "query": {
    "dimensions": ["orders.product_category", "orders.order_date.day"],
    "measures": ["orders.total_revenue"]
  }
}
```

## Filters and ordering

```graphql
query {
  table(
    limit: 100
    timezone: "Asia/Kolkata"
  ) {
    orders(
      orderBy: { store_region: asc, total_revenue: desc }
      where: { status: { equals: "delivered" } }
    ) {
      store_region
      total_revenue
    }
  }
}
```

GraphQL filter differences from REST JSON:

* Numbers are JSON numbers, not strings.
* Null checks use `{ set: false }` instead of `notSet`.
* `in` and `notIn` are supported on string, number, and time fields.
* Time fields have no `onTheDate`. Filter one calendar day with `inDateRange` and the same start and end date, or use `beforeDate`, `afterDate`, `beforeOrOnDate`, or `afterOrOnDate`.
* `@include(if: $var)` and `@skip(if: $var)` work on fields.

Single-day time filter:

```graphql
orders(
  where: {
    order_date: {
      inDateRange: ["2025-01-15", "2025-01-15"]
    }
  }
) {
  total_units
}
```

GraphQL has no `segments[]`. Express segment logic in `where`:

```graphql
query {
  table {
    orders(
      where: {
        status: { equals: "delivered" }
        store_region: { equals: "APAC" }
      }
    ) {
      total_units
    }
  }
}
```

## Multiple models

```graphql
query {
  table(limit: 5) {
    orders {
      store_region
    }
    products {
      product_name
    }
  }
}
```

Cross-model rules are covered in [Cross-model queries](https://v2.dataos.info/references/interfaces/apis/data-product-apis/querying-data-products/advanced/cross-model-queries.md).

## Introspection

```graphql
{
  __schema {
    types {
      name
      kind
      fields {
        name
        type { name }
      }
    }
  }
}
```

## Next steps

Choose the next guide based on how your GraphQL request behaves:

* If the response returns `202`, follow the [Query lifecycle](https://v2.dataos.info/references/interfaces/apis/data-product-apis/querying-data-products/advanced/query-lifecycle.md) to poll the statement and retrieve its result.
* If the request needs fields from related models, see [Cross-model queries](https://v2.dataos.info/references/interfaces/apis/data-product-apis/querying-data-products/advanced/cross-model-queries.md) before combining them.
* If requests are generated or regularly exceed the synchronous wait window, use [REST](https://v2.dataos.info/references/interfaces/apis/data-product-apis/querying-data-products/rest.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://v2.dataos.info/references/interfaces/apis/data-product-apis/querying-data-products/graphql.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
