feat: add field_args property to Info - #4484
Conversation
|
Thanks for adding the Below is the changelog that will be used for the release. This release adds This release was contributed by @rcybulski1122012 in #4484 |
|
I wanted to add this method to my custom Info class but I've got problems with typing - with |
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- In
Info.field_args,get_field_defcan returnNone(e.g. for introspection or invalid fields), so it would be safer to guard against this and either return an empty dict or raise a clearer error rather than unconditionally passing it toget_argument_values. field_argscurrently usesraw_info.field_nodes[0]; if there are multiple field nodes for the same field (e.g. via fragments), consider either documenting that only the first node is used or merging arguments across all nodes to avoid surprising behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `Info.field_args`, `get_field_def` can return `None` (e.g. for introspection or invalid fields), so it would be safer to guard against this and either return an empty dict or raise a clearer error rather than unconditionally passing it to `get_argument_values`.
- `field_args` currently uses `raw_info.field_nodes[0]`; if there are multiple field nodes for the same field (e.g. via fragments), consider either documenting that only the first node is used or merging arguments across all nodes to avoid surprising behavior.
## Individual Comments
### Comment 1
<location path="strawberry/types/info.py" line_range="111-114" />
<code_context>
+ @cached_property
+ def field_args(self) -> dict[str, Any]:
+ """The arguments passed to the current field, converted to strawberry types.
+
+ Scalars are coerced and input types are converted to their proper
+ dataclasses, mirroring the values a resolver receives. Arguments that
+ were not provided are omitted.
+ """
</code_context>
<issue_to_address>
**suggestion:** Clarify behavior regarding defaulted vs explicitly provided arguments
`get_argument_values` typically includes parameters that weren’t explicitly provided but have default values. If `convert_arguments` keeps those, the actual behavior will differ from what’s described. Either filter out defaulted-but-not-provided arguments or update the docstring to clarify that defaulted arguments are included.
</issue_to_address>
### Comment 2
<location path="RELEASE.md" line_range="5-6" />
<code_context>
+---
+
+This release adds `Info.field_args`, a cached property that returns the arguments
+passed to the current field, already converted to strawberry types. Scalars are
+coerced and input types are converted to their proper dataclasses, mirroring the
+values a resolver receives. Both inline literals and variables are handled, and
</code_context>
<issue_to_address>
**nitpick (typo):** Consider capitalizing "Strawberry" here for consistency with the rest of the docs.
For example, the new `field_args` row in `resolvers.md` uses the capitalized phrase "Strawberry types", so it would be good to match that here.
```suggestion
This release adds `Info.field_args`, a cached property that returns the arguments
passed to the current field, already converted to Strawberry types. Scalars are
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
`get_field_def` is not importable from `graphql.execution.execute` on graphql-core 3.3, breaking module import. Look the field up directly off `parent_type.fields` instead, which works on both 3.2 and 3.3. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Guard against an unresolvable field definition (e.g. introspection fields) by returning an empty dict instead of failing. - Clarify in the docstring that defaulted-but-not-provided arguments are included with their defaults, and that arguments are read from the first field node (identical across fragment selections). - Capitalize "Strawberry" in RELEASE.md for consistency. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
graphql-core 3.3's `get_argument_values` expects a `VariableValues` wrapper (with `.coerced`/`.sources`) rather than the plain dict that strawberry's resolve info exposes, causing "'dict' object has no attribute 'coerced'" for variable-based arguments. Wrap the dict in `VariableValues` on 3.3 while leaving 3.2 unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The import is runtime-guarded by IS_GQL_33 but mypy checks against the installed graphql-core 3.2, which lacks the symbol. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Match the codebase convention (see schema/_graphql_core.py) of pairing type: ignore[attr-defined] with pyright: ignore[reportAttributeAccessIssue] for version-specific graphql-core 3.3 imports. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Description
Adds Info.field_args, a cached property returning the current field's arguments converted to strawberry types — the same values a resolver receives (coerced scalars, input dataclasses, Maybe/UNSET sentinels). This lets extensions, permission classes, and generic field logic that only have Info access those values without re-implementing argument conversion.
Handles literals and variables, nested inputs, and lists; omitted args stay UNSET.
Types of Changes
Issues Fixed or Closed by This PR
Info#4249Checklist
Summary by Sourcery
Add a cached field_args property on Info that exposes the current field's arguments in their converted Strawberry types and document and test its behavior.
New Features:
Documentation:
Tests:
Chores: