Skip to content

Fix operation directive argument coercion - #4596

Merged
patrick91 merged 1 commit into
mainfrom
fix/executable-directive-argument-coercion
Aug 29, 2026
Merged

Fix operation directive argument coercion#4596
patrick91 merged 1 commit into
mainfrom
fix/executable-directive-argument-coercion

Conversation

@patrick91

@patrick91 patrick91 commented Aug 29, 2026

Copy link
Copy Markdown
Member

Summary

  • coerce operation directive arguments with graphql-core before invoking resolvers
  • convert coerced values through Strawberry's normal argument conversion path so resolvers receive Python numeric values, enum members, nested input objects, and parsed custom scalars
  • apply directive defaults for omitted variables while preserving explicit null values
  • cover literal and variable inputs, lists, directive chaining, and graphql-core 3.2/3.3 compatibility
  • update directive examples and related test fixtures to use Duck

Testing

  • uv run pytest tests/schema/test_directives.py tests/schema/extensions/schema_extensions tests/schema/extensions/test_apollo.py tests/schema/extensions/test_opentelemetry.py -q (88 passed, 7 skipped, 1 existing xfailed)
  • uv run --with graphql-core==3.3.0rc0 --no-sync pytest tests/schema/test_directives.py -q (26 passed, 1 existing xfailed)
  • mypy under graphql-core 3.2.11 and 3.3.0rc0
  • ruff check and format
  • pre-commit hooks for all changed files

Summary by Sourcery

Fix operation directive argument coercion so directive resolvers receive correctly typed values and preserve GraphQL default and null semantics.

Bug Fixes:

  • Correct operation directive argument handling so resolvers receive GraphQL-coerced and Strawberry-converted values for literals, variables, lists, enums, nested inputs, custom scalars, defaults, and explicit nulls.

Enhancements:

  • Maintain operation directive argument coercion compatibility across graphql-core 3.2 and 3.3.

Documentation:

  • Update operation directive examples and release notes to document correctly typed arguments and default handling.

Tests:

  • Add coverage for directive argument coercion, nested values, custom scalars, directive chaining, variables, defaults, and explicit null values.

Chores:

  • Update related directive and extension fixtures to use Duck consistently.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for adding the RELEASE.md file!

Below is the changelog that will be used for the release.


This release fixes argument handling for operation directive resolvers.

Arguments passed to operation directives now use GraphQL's standard coercion before
your resolver runs. Directive resolvers receive Python numeric values, Strawberry
enum members and nested input objects, and values parsed by custom scalars, whether
clients use literals or variables.

When a client omits a variable, Strawberry now applies the directive argument's
default. Explicit null continues to reach nullable arguments as None.

This release was contributed by @patrick91 in #4596

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@greptile-apps

greptile-apps Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR routes operation-directive arguments through graphql-core coercion and Strawberry’s standard Python argument conversion before invoking directive resolvers.

  • Adds compatibility handling for graphql-core 3.3 variable containers.
  • Covers literals, variables, nested inputs, enums, custom scalars, lists, defaults, explicit nulls, and chained directives.
  • Updates directive documentation, release notes, and related fixtures.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete correctness, compatibility, or security issue identified in the changed paths.

The new flow uses graphql-core for GraphQL-level coercion and Strawberry’s established conversion path for Python values, while preserving variable, default, and explicit-null behavior across supported graphql-core versions.

Important Files Changed

Filename Overview
strawberry/extensions/directives.py Replaces raw directive-node extraction with GraphQL coercion and Strawberry argument conversion, including the graphql-core 3.3 variable-container adapter.
tests/schema/test_directives.py Adds focused coverage for literal and variable coercion, nested inputs, enums, custom scalars, lists, defaults, explicit nulls, and directive chaining.
docs/types/operation-directives.md Updates the operation-directive example and its fixture values consistently.
RELEASE.md Documents the corrected directive argument coercion and conversion behavior.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Directive AST arguments] --> B[graphql-core get_argument_values]
  V[Coerced operation variables] --> B
  B --> C[GraphQL-coerced values and defaults]
  C --> D[Strawberry convert_arguments]
  D --> E[Python inputs, enums, scalars, and lists]
  E --> F[Directive resolver]
Loading

Reviews (1): Last reviewed commit: "Fix executable directive argument coerci..." | Re-trigger Greptile

@patrick91
patrick91 enabled auto-merge (squash) August 29, 2026 11:14
@codspeed-hq

codspeed-hq Bot commented Aug 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 34 untouched benchmarks


Comparing fix/executable-directive-argument-coercion (a9ff490) with main (4fd44aa)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (153b88b) during the generation of this report, so 4fd44aa was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@patrick91
patrick91 merged commit e104af8 into main Aug 29, 2026
83 checks passed
@patrick91
patrick91 deleted the fix/executable-directive-argument-coercion branch August 29, 2026 11:34
@botberry

Copy link
Copy Markdown
Member

This PR was published as 0.324.4. Thank you for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants