Introducing a new way to review your PRs.

Read the announcement

strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓

View on GitHub

21 documents · Updated Nov 18, 2026

docs / operation-execution

Executing GraphQL operations

Strawberry executes a GraphQL document through a Schema by choosing one query or mutation operation, checking it against the schema, and resolving its fields. The execution API supports sync and async work and returns GraphQL data with errors from request preparation or field resolution.

Schema entry points

The Schema connects GraphQL operation types to root Python types. A query uses the required query root. A mutation uses the optional mutation root, so a schema without that root cannot run mutation fields.

Root operation types

Queries read data from the query root. Mutations call fields on the mutation root to change data or cause a side effect. Both roots expose fields whose resolvers produce the values selected by the client.

OperationSchema entry pointMain purpose
queryqueryRead data
mutationmutationChange data or cause a side effect

References: strawberry/…/schema.py• L306-427 strawberry/…/schema.py• L852-958

Request inputs

The async execute and sync execute_sync methods accept the document and the request values needed to run it. The caller can provide variables, a context value for shared request state, a root value for the root resolver, and an operation name when a document contains more than one operation. Strawberry keeps these inputs in an execution context with the allowed operation types, parser options, and validation rules for the request.

The stream entry point accepts the same request state for transports that need a result stream. It can run a query or mutation as one result or route a subscription to repeated results. The caller can also limit the operation types that an entry point may run. The subscription-specific subscribe method is described in Subscriptions and streaming.

References: strawberry/…/schema.py• L615-634 strawberry/…/schema.py• L852-884 strawberry/…/schema.py• L926-958 strawberry/…/schema.py• L1246-1297 strawberry/…/execution.py• L40-61

Operation preparation

Before Strawberry calls a resolver, it prepares the request in a fixed order. It parses the source document, selects the requested operation, checks that its type is allowed, and validates the document against the schema.

The following flow shows the normal path and where pre-execution errors stop resolver work.

flowchart LR
    A[Query or mutation input] --> B[Parse document]
    B --> C[Select operation]
    C --> D[Check allowed operation type]
    D --> E[Validate document]
    E --> F[Invoke resolvers]
    F --> G[Return data and errors]
    B -. parse error .-> H[Return error result]
    C -. selection error .-> H
    D -. disallowed type .-> H
    E -. validation error .-> H

Document parsing

The input query string is parsed into a GraphQL document before execution. A caller or extension can provide an already parsed document through the execution context, which lets request processing reuse parsing work. Parser options travel with the same context and can limit how the document is read. A missing query is a request setup error rather than a resolver error.

Syntax errors become GraphQL errors and prevent resolver invocation. The async and sync paths both place parse errors in the returned result when parsing starts normally. The streaming path also yields a single pre-execution error result instead of starting field work.

References: strawberry/…/schema.py• L187-229 strawberry/…/schema.py• L687-705 strawberry/…/schema.py• L725-743 strawberry/…/schema.py• L1042-1074 strawberry/…/execution.py• L36-39 strawberry/…/execution.py• L58-60

Operation selection

The operation name chooses one named operation from the document. When the caller does not provide a name, Strawberry derives it from the first operation when that operation has a name; an unnamed first operation remains selectable without a name. The selected operation determines whether execution starts at the query or mutation root.

An unknown name or a document without a usable operation cannot be routed to a root type. For execute and execute_sync, these operation-routing errors are raised to the caller. The streaming path converts them to one pre-execution error result so a transport can close the stream cleanly. An operation can also be rejected when its type is not in the allowed set supplied by the caller.

References: strawberry/…/schema.py• L707-713 strawberry/…/schema.py• L745-751 strawberry/…/schema.py• L1050-1073 strawberry/…/schema.py• L1216-1255 strawberry/…/execution.py• L53-95

Document validation

Validation checks the parsed document against the GraphQL schema before any field resolver runs. Strawberry uses the standard GraphQL validation rules by default and can use a request-specific rule set. It also adds rules for Strawberry input behavior. One such rule checks one-of input objects: the input must provide exactly one field, that field must not use a null literal, and a variable used for it must be non-nullable. Extensions can add validation rules or disable document validation for a controlled use case.

Validation errors are pre-execution errors. The result has no resolver data for this stage and contains the validation errors instead. The schema itself is checked when it is created, so schema setup errors are reported before a request is executed.

References: strawberry/…/schema.py• L187-216 strawberry/…/schema.py• L715-723 strawberry/…/schema.py• L753-763 strawberry/…/schema.py• L487-492 strawberry/…/one_of.py• L16-81 strawberry/…/execution.py• L44-50

Resolver execution

After preparation succeeds, Strawberry passes the document to the GraphQL execution engine. The engine walks the selected fields, supplies field arguments, and resolves nested values from the root and from values returned by earlier fields.

Resolver inputs

A resolver receives the GraphQL arguments declared by its field. It can also receive request context, field information, and parent or root data through Strawberry's reserved resolver parameters. The context_value and root_value supplied to execute therefore connect transport-level request state to application-level field work.

Resolver annotations describe GraphQL arguments and return types. Strawberry excludes reserved parameters from the public GraphQL argument list, so request state does not appear as a client-provided argument.

References: strawberry/…/schema.py• L271-304 strawberry/…/schema.py• L806-830

Synchronous and asynchronous work

execute is the async entry point. It waits for awaitable results while still accepting ordinary sync resolvers, so one operation can use both styles. execute_sync requires the complete operation to finish without an awaitable result.

If sync execution reaches async work, Strawberry stops the operation and returns a GraphQL error that states that execution did not complete synchronously. Synchronous execution also rejects incremental delivery because later result frames require async consumption. Use execute when any resolver or downstream operation may need async work.

References: strawberry/…/schema.py• L806-850 strawberry/…/schema.py• L852-924 strawberry/…/schema.py• L975-1007

Resolver errors

An exception raised during field resolution becomes a GraphQL error. GraphQL can still return data from other nullable fields, while the failed field becomes null. A failure in a non-null field can affect the enclosing response through GraphQL null propagation rules.

Strawberry processes execution errors before it exposes the final result. The default process logs them, while a custom Schema.process_errors implementation can change that handling. Extensions can then add result metadata or apply their own result policy.

References: strawberry/…/schema.py• L765-793 strawberry/…/schema.py• L816-850 strawberry/…/schema.py• L1009-1040

Execution results

The normal result is an ExecutionResult with data, errors, and optional extensions. This shape lets a client receive useful data when part of a request fails and lets extensions attach extra response data.

Data and errors

Successful execution returns the selected fields under data. A request-level parse or validation failure returns no resolver data and is marked as a pre-execution error for transports that must stop the operation at once. A field-level failure can return partial data with one or more errors, so clients must inspect both parts of the result.

The result errors are GraphQL errors. Strawberry converts non-GraphQL Python exceptions to that form and keeps the original exception attached for server-side handling. Error messages and locations describe the GraphQL request, while server hooks can still inspect the Python cause.

References: strawberry/…/schema.py• L232-250 strawberry/…/schema.py• L765-793 strawberry/…/schema.py• L915-924 strawberry/…/schema.py• L1021-1040 strawberry/…/execution.py• L98-114

Extension results

Schema extensions observe the operation, parsing, validation, and execution stages. Their result values are merged into the extensions part of the response after execution. Async execution can await extension result hooks. Sync execution rejects an async extension hook because it cannot complete that work in the sync contract.

Streaming transports use a wider result flow. stream sends one result for an ordinary query or mutation and can send several frames for subscriptions or incremental delivery. Its result contract covers ordinary results as well as initial and later incremental results. See Subscriptions and streaming for that transport-facing behavior.

References: strawberry/…/schema.py• L586-613 strawberry/…/schema.py• L879-924 strawberry/…/schema.py• L1042-1214 strawberry/…/schema.py• L1246-1297 strawberry/…/execution.py• L117-130

Operation execution is the central request path, but some workloads need a different result shape or a different data access pattern. These concerns build on the same resolver and execution context rather than replacing the basic query and mutation flow.

References: strawberry/…/schema.py• L1042-1297

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to operation selection must stay aligned with the operation name stored in ExecutionContext and with the operation type allowed by each public entry point.
  • Changes to validation must preserve the distinction between errors found before resolver work and errors raised during field resolution. Input-object rules must also keep their non-null and exactly-one-field contract aligned with schema input behavior.
  • Changes to sync execution must preserve its no-awaitable contract and its error path when an async resolver, incremental result, or extension is encountered.
  • Changes to result handling must keep data, errors, and extension output consistent across execute, execute_sync, and stream.
  • Changes to streaming dispatch must preserve the single-result behavior for queries and mutations and the multi-result behavior for subscriptions and incremental delivery.
  • Changes to error processing must preserve the original exception for server-side logging while allowing the returned GraphQL error to be changed.

Important failure modes

TriggerConsequenceGuard
The document has invalid GraphQL syntaxParsing stops and the result contains an error without resolver dataSend a complete GraphQL document before execution
The operation name does not match a named operationOrdinary execution raises an operation-selection error; streaming yields a pre-execution errorUse the exact operation name or omit it when the document has one intended operation
The selected operation type is not allowed by the callerThe operation is rejected before resolver workSet the allowed operation types to match the transport or entry point
A one-of input object has zero or multiple fieldsValidation fails before resolver workProvide exactly one input field
A one-of input field is null or uses a nullable variableInput coercion validation fails before resolver workProvide a non-null value and use a non-nullable variable
The document fails schema validationNo field resolver runs and the result contains validation errorsValidate the document against the current schema
A transport treats a pre-execution error as a normal execution resultThe transport may keep an operation open after parsing or validation has already failedPreserve the pre-execution error result for transports that must close the operation immediately
execute_sync reaches an async resolver or another awaitableThe result contains GraphQL execution failed to complete synchronously.Use execute for operations that may perform async work
execute_sync reaches incremental deliveryExecution fails because later frames need async consumptionUse execute for operations that use @defer or @stream
A nullable resolver raises an exceptionThe field becomes null and the response also contains an errorInspect both data and errors; log or handle the original exception on the server

Key files

FileWhy to read it
strawberry/…/schema.pyMain Schema entry points and the parse, select, validate, execute, stream, and result flow
strawberry/…/one_of.pyValidation contract for one-of input objects during document validation
strawberry/…/execution.pyRequest state, operation selection, and the result shapes used by normal, pre-execution, and streaming execution
strawberry/…/operation.pyOperation name lookup and default first-operation selection
strawberry/…/resolver.pyResolver argument discovery and reserved request parameters
strawberry/…/base.pyPublic execution method contracts and default error processing
strawberry/…/runner.pyExtension lifecycle and response metadata handling
strawberry/…/is_awaitable.pyAwaitable detection used by the GraphQL execution path
tests/…/test_execution.pyGuarantees for validation, error handling, logging, and partial responses
tests/…/test_execution_errors.pyGuarantees for parse errors and the sync-versus-async contract