-
-
Notifications
You must be signed in to change notification settings - Fork 612
Open
Description
Currently there is no easy way to access field arguments (or it's not documented well enough) outside the resolver.
Feature Request Type
- Core functionality
- Alteration (enhancement/optimization) of existing feature(s)
- New behavior
Description
In my project I implemented a function that retrieves the arguments from info object but it would be much more convenient if it was a part of Info object - it would ease the caching too.
IDK if there is a use case for that in strawberry but when using strawberry_django it would ease the filtering based on user arguments in prefetch_related and annotate.
It would require only to implement a simple property on Info class
from typing import Any
from graphql import GraphQLResolveInfo, get_argument_values
from graphql.execution.execute import get_field_def
@dataclasses.dataclass
class Info(Generic[ContextType, RootValueType]):
...
@cached_property
def field_arguments(self) -> dict[str, Any]:
field_def = get_field_def(self._raw_info.schema, self._raw_info.parent_type, self._raw_info.field_nodes[0])
if not field_def:
return {}
return get_argument_values(field_def, self._raw_info.field_nodes[0], self._raw_info.variable_values) Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels