When setting a parameter value using strawberry.field(description=..., default=...)
, if the typing is bool
and the default value is False
/ True
(correct typing), the schema is not parsed correctly and returns an error on runtime when trying to fetch the schema.
@strawberry.type
class SomeType:
@strawberry.field(description="Return hello")
def hello(self, info: Info, problematic_field: bool = strawberry.field(description="Problematic field in schema", default=False)) -> Text:
return "hello"
raises:
GraphQL request:61:7
60 | type { ...TypeRef }
61 | defaultValue
| ^
62 |
Traceback (most recent call last):
File "/home/aponace/projects/cnside/venv/lib/python3.8/site-packages/graphql/execution/execute.py", line 521, in execute_field
result = resolve_fn(source, info, **args)
File "/home/aponace/projects/cnside/venv/lib/python3.8/site-packages/strawberry/extensions/base_extension.py", line 59, in resolve
return _next(root, info, *args, **kwargs)
File "/home/aponace/projects/cnside/venv/lib/python3.8/site-packages/strawberry/extensions/base_extension.py", line 59, in resolve
return _next(root, info, *args, **kwargs)
File "/home/aponace/projects/cnside/venv/lib/python3.8/site-packages/strawberry/extensions/base_extension.py", line 59, in resolve
return _next(root, info, *args, **kwargs)
[Previous line repeated 1 more time]
File "/home/aponace/projects/cnside/venv/lib/python3.8/site-packages/graphql/type/introspection.py", line 485, in default_value
value_ast = ast_from_value(item[1].default_value, item[1].type)
File "/home/aponace/projects/cnside/venv/lib/python3.8/site-packages/graphql/utilities/ast_from_value.py", line 63, in ast_from_value
ast_value = ast_from_value(value, type_.of_type)
File "/home/aponace/projects/cnside/venv/lib/python3.8/site-packages/graphql/utilities/ast_from_value.py", line 108, in ast_from_value
serialized = type_.serialize(value) # type: ignore
File "/home/aponace/projects/cnside/venv/lib/python3.8/site-packages/graphql/type/scalars.py", line 218, in serialize_boolean
raise GraphQLError(
graphql.error.graphql_error.GraphQLError: Boolean cannot represent a non boolean value: <StrawberryField instance>
Other types work fine even when setting problematic_field: Text = strawberry.field(default=False)
with a clear type mismatch the schema is loaded correctly.
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