Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Release 2.0

Compare
Choose a tag to compare
@bellini666 bellini666 released this 25 Jan 19:14
· 120 commits to main since this release
17d5c55

What's Changed

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:

  1. The Node.resolve_connection classmethod has been removed. If you want to personalize how the connection is created and filtered, you can subclass the Connection class and override the from_nodes classmethod

  2. The Node.CONNECTION_CLASS and Connection.EDGE_CLASS are gone! The connection class will be retrieved from the type itself. For example, this will use CustomConnection for the some_connection field:

@strawberry.type
class CustomConnection(relay.Connection[relay.NodeType]):
    ...

@strawberry.type
class Query:
    some_connection: CustomConnection[SomeType] = relay.connection()
  1. 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