feat: pass resolved field arguments to prefetch_related callables#881
feat: pass resolved field arguments to prefetch_related callables#881bellini666 wants to merge 1 commit intomainfrom
Conversation
Prefetch callables that declare parameters beyond `info` now automatically receive the field's resolved GraphQL arguments as keyword arguments. Also adds `strawberry_django.get_field_arguments(info)` as a public utility for resolving field arguments without raw AST access. Closes #863
Reviewer's GuideAdds argument-aware handling of prefetch-related callables in the optimizer and exposes a public get_field_arguments(info) utility, ensuring prefetch callables can receive resolved field arguments while remaining backwards-compatible with existing info-only callables. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Thanks for adding the Below is the changelog that will be used for the release. Prefetch callables can now receive resolved field arguments as keyword parameters. If a Also adds This release was contributed by @bellini666 in #881 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #881 +/- ##
==========================================
+ Coverage 91.56% 91.60% +0.03%
==========================================
Files 49 49
Lines 4588 4620 +32
==========================================
+ Hits 4201 4232 +31
- Misses 387 388 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| return schema.config.info_class(raw_info, field) | ||
|
|
||
|
|
||
| def get_field_arguments(info: Info) -> dict[str, Any]: |
There was a problem hiding this comment.
This is the version that Claude generated for me 😅
```python
def _get_field_args(raw_info: GraphQLResolveInfo) -> dict[str, Any]:
field_def = get_field_def(raw_info.schema, raw_info.parent_type, raw_info.field_nodes[0])
raw_args = get_argument_values(field_def, raw_info.field_nodes[0], raw_info.variable_values)
strawberry_schema = getattr(raw_info.schema, "_strawberry_schema", None) or raw_info.schema.extensions.get(
GraphQLCoreConverter.DEFINITION_BACKREF
)
schema_converter = getattr(strawberry_schema, "schema_converter", None)
strawberry_field = field_def.extensions.get(GraphQLCoreConverter.DEFINITION_BACKREF)
if not schema_converter:
raise RuntimeError(
"Failed to find strawberry schema for field. Ensure the schema is a strawberry.Schema instance."
)
if not strawberry_field:
raise RuntimeError("Failed to find strawberry field definition. Arguments cannot be correctly converted.")
return convert_arguments(
value=raw_args,
arguments=strawberry_field.arguments,
config=schema_converter.config,
scalar_registry=schema_converter.scalar_registry,
)I don't know the library internals well enough to tell whether they behave differently
Summary
infonow automatically receive the field's resolved GraphQL arguments as keyword arguments (viainspect.signaturedispatch)strawberry_django.get_field_arguments(info)— a public utility for resolving the current field's GraphQL arguments fromInfowithout raw AST accesslambda info: ...callables continue to work unchangedCloses #863
Test plan
lambda info: ...still works**kwargscallable receives all argsget_field_arguments()utility test🤖 Generated with Claude Code
Summary by Sourcery
Allow optimizer prefetch callables to receive resolved field arguments and expose a public helper for accessing field arguments from Info.
New Features:
Enhancements:
Documentation:
Tests: