Add strawberry.Info support to schema extensions - #4604
Conversation
|
Thanks for adding the Below is the changelog that will be used for the release. This release adds Annotating Run This release was contributed by @patrick91 in #4604 |
There was a problem hiding this comment.
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.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Greptile SummaryThe PR allows schema-extension resolvers annotated with
Confidence Score: 5/5The 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.
|
| 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
Reviews (1): Last reviewed commit: "Add Strawberry Info support to schema ex..." | Re-trigger Greptile
Summary
SchemaExtension.resolveimplementations annotated withstrawberry.Infoto receive the schema's configured Info classGraphQLResolveInfobehavior temporarily while emitting a thread-safe, once-per-class deprecation warningstrawberry upgrade schema-extension-info .codemod and report cases that need manual reviewLegacy 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, soInfo._fieldis optional and affected public properties have documented fallbacks.Related to #4242.
Tests
uv run pytest tests/schema -quv run pytest tests/schema/extensions/schema_extensions tests/extensions -quv run --isolated --with 'graphql-core==3.3.0rc0' pytest tests/schema/extensions/schema_extensions/test_info.py tests/schema/test_info.py -quv run mypy --config-file mypy.ini strawberry/schema/schema.py strawberry/schema/schema_converter.pyuv run pre-commit run --all-filestests/benchmarks/test_execute_with_extensions.pyagainst the previous PR revision andorigin/main