Relay Support
You can use the official strawberry relay integration directly with django types like this:
Behind the scenes this extension is doing the following for you:
- Automatically resolve the
relay.NodeID
field using the modelβs pk - Automatically generate resolves for connections that doesnβt define one. For example,
some_model_conn
andsome_model_conn_with_total_count
will both define a custom resolver automatically that returnsSomeModel.objects.all()
. - Integrate connection resolution with all other features available in this lib. For example, filters , ordering and permissions can be used together with connections defined by strawberry django.
You can also define your own relay.NodeID
field and your resolve, in the same way as
some_model_conn_with_resolver
is doing. In those cases, they will not be overridden.
Tip
If you are only working with types inheriting from relay.Node
and GlobalID
for identifying objects, you might want to set MAP_AUTO_ID_AS_GLOBAL_ID=True
in your strawberry django settings to make sure auto
fields gets
mapped to GlobalID
on types and filters.
Also, this lib exposes a strawberry_django.relay.ListConnectionWithTotalCount
, which works
the same way as strawberry.relay.ListConnection
does, but also exposes a
totalCount
attribute in the connection.
For more customization options, like changing the pagination algorithm, adding extra fields
to the Connection
/Edge
type, take a look at the
official strawberry relay integration
as those are properly explained there.