Schema Directives
Strawberry supports schema directives , which are directives that donβt change the behavior of your GraphQL schema but instead provide a way to add additional metadata to it.
For example our Apollo Federation integration is based on schema directives.
Letβs see how you can implement a schema directive in Strawberry, here we are
creating a directive called keys
that can be applied to
Object types definitions and accepts one parameter called
fields
. Note that directive names, by default, are converted to camelCase on
the GraphQL schema.
Hereβs how we can use it in our schema:
This will result in the following schema:
Overriding field names
You can use strawberry.directive_field
to override the name of a field:
Locations
Schema directives can be applied to many different parts of a schema. Hereβs the list of all the allowed locations:
Name | Description | |
---|---|---|
SCHEMA | strawberry.Schema | The definition of a schema |
SCALAR | strawberry.scalar | The definition of a scalar |
OBJECT | strawberry.type | The definition of an object type |
FIELD_DEFINITION | strawberry.field | The definition of a field on an object type or interface |
ARGUMENT_DEFINITION | strawberry.argument | The definition of an argument |
INTERFACE | strawberry.interface | The definition of an interface |
UNION | strawberry.union | The definition of an union |
ENUM | strawberry.enum | The definition of a enum |
ENUM_VALUE | strawberry.enum_value | The definition of a enum value |
INPUT_OBJECT | strawberry.input | The definition of an input object type |
INPUT_FIELD_DEFINITION | strawberry.field | The definition of a field on an input type |