Release 2.0
What's Changed
- BREAKING CHANGE: Relay refactor by @bellini666 in #167
Relay BREAKING CHANGES
The relay integration has been refactored to simplify its usage and allow for better customization.
If you were not defining any custom Connection
/Edge
types, this should not affect you! Otherwise, follow this directions to adjust your code:
-
The
Node.resolve_connection
classmethod has been removed. If you want to personalize how the connection is created and filtered, you can subclass theConnection
class and override the from_nodes classmethod -
The
Node.CONNECTION_CLASS
andConnection.EDGE_CLASS
are gone! The connection class will be retrieved from the type itself. For example, this will useCustomConnection
for thesome_connection
field:
@strawberry.type
class CustomConnection(relay.Connection[relay.NodeType]):
...
@strawberry.type
class Query:
some_connection: CustomConnection[SomeType] = relay.connection()
- The relay resolver (when using it as a
@relay.connection
) accepts both an iterable of a node implemented type or a connection directly. For example:
@strawberry.type
class Query:
@relay.connection
def some_connection(self, some_extra_arg: str) -> Iterable[SomeType]:
...
@relay.connection
def some_connection(self, first: int | None = None, last: int | None = None, ...) -> Connection[SomeType]:
...
Both will return a SomeTypeConnection
, but in the iterable one you just need to give it the iterable itself and the connection will filter it with slices for you. In the second example you are responsible for paginating it yourself.
obs. That iterable have its __getitem__
overrided for custom slicing. For example, when returning a django QuerySet
the slice will translate to a limit
/office
in the query and retrieve just the paginated items for better performance.
Full Changelog: v1.35.2...v2.0