The problem occurs when using new-style lazy annotations (with from __future__ import annotations
) wrapped into a List[]
:
# c.py
@strawberry.type
class C:
id: strawberry.ID
# d.py
from __future__ import annotations
from typing import TYPE_CHECKING, List
from typing_extensions import Annotated
import strawberry
if TYPE_CHECKING:
from tests.c import C
@strawberry.type
class D:
id: strawberry.ID
@strawberry.field
async def c_list(self) -> List[Annotated[C, strawberry.lazy("tests.c")]]:
...
Error:
E strawberry.exceptions.unresolved_field_type.UnresolvedFieldTypeError:
Could not resolve the type of 'c_list'. Check that the class is accessible from the global module scope.
strawberry/schema/schema_converter.py:321: UnresolvedFieldTypeError
However, if you add another field, which is just Annotated[C, ...]
, everything is fine:
@strawberry.type
class D:
id: strawberry.ID
@strawberry.field
async def c(self) -> Annotated[C, strawberry.lazy("tests.c")]:
...
@strawberry.field
async def c_list(self) -> List[Annotated[C, strawberry.lazy("tests.c")]]:
...
Also, it works as expected with the old-school annotations, List[Annotated["C", ...]]
. I added all the necessary test cases in #2895.
Related PR with the feature:
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too