Skip to content

Typing behavior change in strawberry 0.156.2 #2534

Closed
@csuriano23

Description

@csuriano23

The @strawberry.field annotation behavior has changed at typing level between strawberry 0.156.1 and 0.156.2. It should now be a callable

Describe the Bug

Consider this simple code:

import strawberry


@strawberry.type
class Author:
    name: str


@strawberry.type
class Query:
    @strawberry.field
    async def get_authors(self) -> list[Author]:
        return [
            Author(name="Michael Crichton")
        ]

Running mypy on this is ok for strawberry 0.156.1.

On strawberry 0.156.2 this gives an error:

error: Argument 1 to "field" has incompatible type "Callable[[Query], Coroutine[Any, Any, List[Author]]]"; expected "Union[StrawberryResolver[<nothing>], Callable[..., <nothing>], Callable[..., Awaitable[<nothing>]], staticmethod[<nothing>], classmethod[<nothing>]]"  [arg-type]

This is probably due to the declaration of the callable on awaitable (https://github.com/strawberry-graphql/strawberry/pull/2528/files), since switching to field as this is ok:

import strawberry


@strawberry.type
class Author:
    name: str


@strawberry.type
class Query:
    @strawberry.field()
    async def get_authors(self) -> list[Author]:
        return [
            Author(name="Michael Crichton")
        ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions