Using None as an annotation directly (not None | Something, just None) on a data class-style field with strawberry.field() doesn't work. Various other similar incantations do work.
Traceback (most recent call last):
File "/lib/python311.zip/_pyodide/_base.py", line 573, in eval_code_async
await CodeRunner(
File "/lib/python311.zip/_pyodide/_base.py", line 395, in run_async
await coroutine
File "<exec>", line 21, in <module>
File "/lib/python3.11/site-packages/strawberry/schema/schema.py", line 162, in __init__
raise error.__cause__ from None
File "/lib/python3.11/site-packages/graphql/type/definition.py", line 808, in fields
fields = resolve_thunk(self._fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/graphql/type/definition.py", line 300, in resolve_thunk
return thunk() if callable(thunk) else thunk
^^^^^^^
File "/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 525, in <lambda>
fields=lambda: self.get_graphql_fields(object_type),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 382, in get_graphql_fields
return _get_thunk_mapping(
^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 132, in _get_thunk_mapping
raise UnresolvedFieldTypeError(type_definition, field)
strawberry.exceptions.unresolved_field_type.UnresolvedFieldTypeError: Could not resolve the type of 'broken'. Check that the class is accessible from the global module scope.
If I comment out broken, then strawberry accepts this code, and the resulting schema is what I expect ✅
This annotation is weird but is meaningful/semi-useful (for historical reasons, we have an input type that has no real fields, so we have _unused: None = strawberry.field(default=None) instead.
Upvote & Fund
We're using Polar.sh so you can upvote and help fund this issue.
We receive the funding once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog.
Describe the Bug
Using
None
as an annotation directly (notNone | Something
, justNone
) on a data class-style field withstrawberry.field()
doesn't work. Various other similar incantations do work.If I comment out
broken
, then strawberry accepts this code, and the resulting schema is what I expect ✅(The fact that
"None"
works means that it also works to run withfrom __future__ import annotations
to have all annotations be deferred strings.)System Information
Additional Context
This annotation is weird but is meaningful/semi-useful (for historical reasons, we have an input type that has no real fields, so we have
_unused: None = strawberry.field(default=None)
instead.Upvote & Fund