Skip to content

🍓 0.162.0

Compare
Choose a tag to compare
@botberry botberry released this 10 Mar 12:23
· 745 commits to main since this release

Adds support for a custom field using the approach specified in issue #2168.
Field Extensions may be used to change the way how fields work and what they return.
Use cases might include pagination, permissions or other behavior modifications.

from strawberry.extensions import FieldExtension


class UpperCaseExtension(FieldExtension):
    async def resolve_async(
        self, next: Callable[..., Awaitable[Any]], source: Any, info: Info, **kwargs
    ):
        result = await next(source, info, **kwargs)
        return str(result).upper()


@strawberry.type
class Query:
    @strawberry.field(extensions=[UpperCaseExtension()])
    async def string(self) -> str:
        return "This is a test!!"
query {
    string
}
{
  "string": "THIS IS A TEST!!"
}

Releases contributed by @erikwrede via #2567