Private Fields
Private (external) fields can provide local context for later resolution. These fields will act as plain fields so will not be exposed in the GraphQL API.
Some uses include:
- Context that relies upon field inputs.
- Avoiding fully materializing an object hierarchy (lazy resolution)
Defining a private field
Specifying a field with strawberry.Private[...]
will desigate it as internal
and not for GraphQL.
Example
Consider the following type, which can accept any Python object and handle converting it to string, representation, or templated output:
The Private[...]
type lets Strawberry know that this field is not a GraphQL
field. “value” is a regular field on the class, but it is not exposed on the
GraphQL API.
Queries can then select the fields and formats desired, but formatting only happens as requested: