Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow connection to be used without relay for generic cursor pagination #3669

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Release type: minor

This release moves the `Connection` implementation outside the relay package,
allowing it to be used for general-purpose cursor pagination.

The following now can be imported from `strawberry.pagination`:

- `Connection` - base generic class for implementing connections
- `ListConnection` - a limit-offset implementation of the connection
- `connection` - field decorator for creating connections

Those can still be used together with the relay package, but importing from it
is now deprecated.

You can read more about connections in the
[Strawberry Connection Docs](https://strawberry.rocks/docs/guides/pagination/connections).
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
---
title: Relay wrong resolver annotation Error
title: Connection wrong resolver annotation Error
---

# Relay wrong resolver annotation error
# Connection wrong resolver annotation error

## Description

This error is thrown when a field on a relay connection was defined with a
resolver that returns something that is not compatible with pagination.
This error is thrown when a field on a connection was defined with a resolver
that returns something that is not compatible with pagination.

For example, the following code would throw this error:

```python
from typing import Any

import strawberry
from strawberry import relay
from strawberry.pagination import connection


@strawberry.type
class MyType(relay.Node): ...
class MyType(Node): ...


@strawberry.type
class Query:
@relay.connection(relay.Connection[MyType])
@connection(Connection[MyType])
def some_connection_returning_mytype(self) -> MyType: ...

@relay.connection(relay.Connection[MyType])
@connection(Connection[MyType])
def some_connection_returning_any(self) -> Any: ...
```

Expand All @@ -53,22 +53,22 @@ For example:
from typing import Any

import strawberry
from strawberry import relay
from strawberry.pagination import connection, Connection


@strawberry.type
class MyType(relay.Node): ...
class MyType: ...


@strawberry.type
class Query:
@relay.connection(relay.Connection[MyType])
@connection(Connection[MyType])
def some_connection(self) -> Iterable[MyType]: ...
```

<Note>
Note that if you are returning a type different than the connection type, you
will need to subclass the connection type and override its `resolve_node`
method to convert it to the correct type, as explained in the [relay
guide](../guides/relay).
method to convert it to the correct type, as explained in the [pagination
guide](../guides/pagination).
</Note>
Loading
Loading