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

# Schema and execution

> Reference for schema construction, validation, and execution.

## `build_schema`

Compiles decorated query, mutation, and subscription roots into a `Schema`. It also
accepts additional reachable types, a type registry, and `SchemaConfig`.

```python theme={null}
schema = build_schema(
    query=QueryRoot,
    mutation=MutationRoot,
    types=[AuditEvent],
    config=SchemaConfig(auto_camel_case=True),
)
```

`Schema(query=...)` is a convenient constructor that performs the same compilation
when passed decorated Python classes.

## `execute`

```python theme={null}
result = await execute(
    schema,
    query,
    variable_values={"id": "42"},
    context=request_context,
    operation_name="GetUser",
)
```

The query may be a string, `Source`, or parsed `DocumentNode`. Execution parses when
needed, selects an operation, validates, coerces variables, resolves fields, completes
values, and returns `ExecutionResult`.

Pass `mask_errors=True` (with an optional `mask_message`) to replace unexpected
resolver errors with a generic message in the response; explicit `GraphQLError`s pass
through and the original exception stays on `GraphQLError.original_error`.

## `subscribe`

```python theme={null}
stream = await subscribe(schema, "subscription { counter(to: 2) }", context=ctx)
async for result in stream:
    ...
```

Runs a subscription and returns an async iterator yielding one `ExecutionResult` per
source event, or a single `ExecutionResult` (with `executed=False`) when the document
is invalid or is not a subscription. See [Subscriptions](/protocol/subscriptions).

## `execute_incremental`

```python theme={null}
async for payload in execute_incremental(schema, query):
    ...
```

Executes an operation as an incremental-delivery stream of JSON payloads for
`@defer` / `@stream`. See [Incremental delivery](/protocol/incremental-delivery).

## Schema extensions

`Schema(query=..., extensions=[...])` (and `build_schema(..., extensions=[...])`)
attach [schema extensions](/data/schema-extensions) that observe the operation
lifecycle and wrap field resolution.

## `validate` and `parse`

Use `parse(source)` when an application benefits from retaining the GraphQL AST.
Use `validate(schema, document)` to inspect validation errors without executing.
