Skip to content

Access to field arguments via Info #4249

@rcybulski1122012

Description

@rcybulski1122012

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)  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions