Private Strawberry Field Error
Description
This error is thrown when using both strawberry.Private[Type] and
strawberry.field on the same field, for example the following code will throw
this error:
import strawberry
@strawberry.typeclass Query: name: str age: strawberry.Private[int] = strawberry.field(name="ageInYears")
schema = strawberry.Schema(query=Query) This happens because a strawberry.Private field is not going to be exposed in
the GraphQL schema, so using strawberry.field on that field wonβt be useful,
since it is meant to be used to change information about a field that is exposed
in the GraphQL schema.
This makes sense, but now we donβt have a way to do something like: strawberry.Private[list[str]] = strawberry.field(default_factory=list) (workaround is to use dataclasses.field, explained below)
How to fix this error
You can fix this error by either removing the strawberry.Private annotation or
by removing the strawberry.field usage. If you need to specify a default value
using default_factory you can use dataclasses.field instead of
strawberry.field . For example:
import strawberryimport dataclasses
@strawberry.typeclass Query: name: str tags: strawberry.Private[str] = dataclasses.field(default_factory=list)
schema = strawberry.Schema(query=Query)