Add input clean methods - #4554
Conversation
|
Thanks for adding the Below is the changelog that will be used for the release. This release adds lifecycle hooks for input objects. Input objects can now define a synchronous or asynchronous This release was contributed by @Speedy1991 in #4554 |
| # explicitly to the extensions | ||
| field_kwargs.pop("info") | ||
|
|
||
| input_clean_methods = run_input_clean_methods( | ||
| [*field_args, *field_kwargs.values()], info | ||
| ) |
There was a problem hiding this comment.
Argument mapping skips input cleaning
When a field extension such as InputMutationExtension unwraps the containing input in map_arguments, this code traverses only the already-transformed arguments, causing the containing input object's clean method to be skipped.
Knowledge Base Used: Schema Core: Building a GraphQL Schema from Python Types
There was a problem hiding this comment.
Meh, I wasn't aware of this extension. 😅
This is going to make things a lot more complicated, @patrick91.
Greptile SummaryAdds opt-in synchronous and asynchronous lifecycle hooks for Strawberry input objects.
Confidence Score: 3/5This PR should not merge until clean hooks are scheduled before argument-mapping extensions so extensions cannot cause the containing input hook to be skipped. The new call site traverses arguments only after extension mapping, and the existing input-mutation extension explicitly removes the containing input object at that earlier stage. Files Needing Attention: strawberry/schema/schema_converter.py, tests/schema/test_input.py
|
| Filename | Overview |
|---|---|
| strawberry/schema/schema_converter.py | Integrates clean-hook execution into field resolution, but schedules it after extension argument mapping can remove the input object. |
| strawberry/types/input.py | Implements sequential child-before-parent traversal with synchronous fast-path and asynchronous continuation. |
| tests/schema/test_input.py | Covers core ordering and async behavior but does not cover an argument-mapping extension that unwraps the containing input before cleaning. |
| docs/types/input-types.md | Documents synchronous normalization, asynchronous request-scoped loading, and nested cleaning behavior. |
Sequence Diagram
sequenceDiagram
participant GQL as graphql-core
participant Args as Argument conversion
participant Ext as Field extensions
participant Clean as Input clean hooks
participant Resolver
GQL->>Args: Coerce field arguments
Args->>Ext: map_arguments(kwargs)
Ext-->>Args: Transformed arguments
Args->>Clean: Traverse remaining inputs
Clean-->>Resolver: Invoke extension chain and resolver
Reviews (1): Last reviewed commit: "implement input clean methods" | Re-trigger Greptile
Description
Adds opt-in
clean(info)methods for Strawberry input types. Clean methods run after input coercion and before field extensions and resolver execution. They support both synchronous and asynchronous implementations, receive the resolverInfo, and process nested inputs before their containing input.Also adds documentation for synchronous normalization, async request-scoped DataLoader hydration, and nested input validation.
Types of Changes
Issues Fixed or Closed by This PR
Fixes #4552
Checklist
Summary by Sourcery
Introduce lifecycle clean hooks for input objects that run between input coercion and resolver execution.
New Features:
Build:
Documentation:
Tests: