Skip to content

Add strawberry.Info support to schema extensions - #4604

Draft
patrick91 wants to merge 3 commits into
mainfrom
schema-extension-info
Draft

Add strawberry.Info support to schema extensions#4604
patrick91 wants to merge 3 commits into
mainfrom
schema-extension-info

Conversation

@patrick91

@patrick91 patrick91 commented Aug 31, 2026

Copy link
Copy Markdown
Member

Summary

  • allow SchemaExtension.resolve implementations annotated with strawberry.Info to receive the schema's configured Info class
  • preserve raw GraphQLResolveInfo behavior temporarily while emitting a thread-safe, once-per-class deprecation warning
  • reuse the same Info object through modern middleware and the field resolver, unwrapping only at legacy or graphql-core-only boundaries
  • add a behavior-preserving strawberry upgrade schema-extension-info . codemod and report cases that need manual review
  • document the migration, introspection-field behavior, and an LLM migration prompt

Legacy and Info-aware extensions can coexist in the same middleware chain during the migration period. The raw behavior is deprecated now and will be removed in Strawberry 1.0.

Info-aware middleware continues to run for graphql-core-only fields such as introspection fields. Those fields have no corresponding StrawberryField, so Info._field is optional and affected public properties have documented fallbacks.

Related to #4242.

Tests

  • uv run pytest tests/schema -q
  • uv run pytest tests/schema/extensions/schema_extensions tests/extensions -q
  • uv run --isolated --with 'graphql-core==3.3.0rc0' pytest tests/schema/extensions/schema_extensions/test_info.py tests/schema/test_info.py -q
  • uv run mypy --config-file mypy.ini strawberry/schema/schema.py strawberry/schema/schema_converter.py
  • uv run pre-commit run --all-files
  • local CodSpeed comparison of tests/benchmarks/test_execute_with_extensions.py against the previous PR revision and origin/main

@github-actions

github-actions Bot commented Aug 31, 2026

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 adds strawberry.Info support to schema extension resolvers.

Annotating SchemaExtension.resolve with strawberry.Info now passes the same
configured Info type used by field resolvers. Existing unannotated and
GraphQLResolveInfo extension resolvers continue to receive the graphql-core
object, with a deprecation warning ahead of Strawberry 1.0.

Run strawberry upgrade schema-extension-info . to opt direct schema extension
subclasses into Strawberry Info while preserving their existing raw Info
behavior.

This release was contributed by @patrick91 in #4604

@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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="strawberry/schema/schema.py" line_range="625-628" />
<code_context>
+            extension_type = type(extension)
+            resolver_module = extension_type.resolve.__module__
+            if (
+                extension_type not in _WARNED_GRAPHQL_INFO_EXTENSIONS
+                and not resolver_module.startswith("strawberry.extensions.")
+            ):
+                _WARNED_GRAPHQL_INFO_EXTENSIONS.add(extension_type)
+                warnings.warn(
+                    (
</code_context>
<issue_to_address>
**nitpick (bug_risk):** The check-then-add sequence on the process-global `_WARNED_GRAPHQL_INFO_EXTENSIONS` set is not synchronized, so two requests that execute the first legacy call for the same extension class concurrently both emit the deprecation warning instead of warning once per class.

**Triggers:** When two threads concurrently execute schemas using the same legacy extension class for the first time.

**Suggested fix:** Protect the membership check and insertion with a lock, or use a thread-safe once-per-class warning mechanism.
</issue_to_address>

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.

Comment thread strawberry/schema/schema.py Outdated
@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR allows schema-extension resolvers annotated with strawberry.Info to receive the schema’s configured Info class while preserving legacy raw GraphQLResolveInfo behavior. It also adds migration tooling and documentation.

  • Detects Info-aware schema-extension resolver signatures and adapts mixed legacy/new middleware chains.
  • Makes Info safe to construct for graphql-core-only fields such as introspection fields.
  • Adds a schema-extension-info upgrade codemod with warnings for cases requiring manual review.
  • Adds sync, async, custom Info, compatibility, introspection, CLI, codemod, and type-checking coverage.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code defect identified.

The middleware preserves raw graphql-core boundaries while supplying configured Strawberry Info instances to opted-in extensions, and the codemod and optional-field behavior are covered across the relevant compatibility paths.

Important Files Changed

Filename Overview
strawberry/schema/schema.py Adds annotation-sensitive middleware adaptation, configured Info construction, legacy compatibility warnings, and raw-info forwarding between mixed extension types.
strawberry/extensions/base_extension.py Adds cached detection of whether an extension resolver declares Strawberry’s reserved Info parameter.
strawberry/types/info.py Supports absent Strawberry field metadata for graphql-core-only fields with explicit property fallbacks.
strawberry/codemods/schema_extension_info.py Adds a behavior-preserving codemod for direct SchemaExtension subclasses, including alias/import handling and manual-review warnings.
strawberry/cli/commands/upgrade/init.py Registers the new codemod and reports transformation warnings alongside the existing upgrade summary.
tests/schema/extensions/schema_extensions/test_info.py Covers configured Info classes, async execution, raw forwarding, mixed middleware, warning deduplication, and introspection fields.

Sequence Diagram

sequenceDiagram
    participant Core as graphql-core
    participant Adapter as Schema middleware adapter
    participant Extension as Info-aware extension
    participant Next as Next middleware/resolver
    Core->>Adapter: root, GraphQLResolveInfo, arguments
    Adapter->>Adapter: Look up StrawberryField
    Adapter->>Adapter: Construct configured Info class
    Adapter->>Extension: resolve(next, root, strawberry.Info, arguments)
    Extension->>Adapter: next(root, Info or raw info, arguments)
    Adapter->>Adapter: Unwrap Info to GraphQLResolveInfo
    Adapter->>Next: root, GraphQLResolveInfo, arguments
    Next-->>Extension: field result
    Extension-->>Core: field result
Loading

Reviews (1): Last reviewed commit: "Add Strawberry Info support to schema ex..." | Re-trigger Greptile

@patrick91
patrick91 marked this pull request as draft August 31, 2026 21:39
@codspeed-hq

codspeed-hq Bot commented Aug 31, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 34 untouched benchmarks


Comparing schema-extension-info (3b8463a) with main (2ebb797)1

Open in CodSpeed

Footnotes

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

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.

1 participant