Skip to content

Commit ddcc952

Browse files
committed
feat: Allow connection to be used without relay for generic cursor pagination
1 parent d504428 commit ddcc952

23 files changed

+1620
-1774
lines changed

RELEASE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Release type: minor
2+
3+
This release moves the `Connection` implementation outside the relay package,
4+
allowing it to be used for general-purpose cursor pagination.
5+
6+
The following now can be imported from `strawberry.pagination`:
7+
8+
- `Connection` - base generic class for implementing connections
9+
- `ListConnection` - a limit-offset implementation of the connection
10+
- `connection` - field decorator for creating connections
11+
12+
Those can still be used together with the relay package, but importing from it
13+
is now deprecated.
14+
15+
You can read more about connections in the
16+
[Strawberry Connection Docs](https://strawberry.rocks/docs/guides/pagination/connections).
File renamed without changes.

docs/errors/relay-wrong-resolver-annotation.md renamed to docs/errors/connection-wrong-resolver-annotation.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
---
2-
title: Relay wrong resolver annotation Error
2+
title: Connection wrong resolver annotation Error
33
---
44

5-
# Relay wrong resolver annotation error
5+
# Connection wrong resolver annotation error
66

77
## Description
88

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

1212
For example, the following code would throw this error:
1313

1414
```python
1515
from typing import Any
1616

1717
import strawberry
18-
from strawberry import relay
18+
from strawberry.pagination import connection
1919

2020

2121
@strawberry.type
22-
class MyType(relay.Node): ...
22+
class MyType(Node): ...
2323

2424

2525
@strawberry.type
2626
class Query:
27-
@relay.connection(relay.Connection[MyType])
27+
@connection(Connection[MyType])
2828
def some_connection_returning_mytype(self) -> MyType: ...
2929

30-
@relay.connection(relay.Connection[MyType])
30+
@connection(Connection[MyType])
3131
def some_connection_returning_any(self) -> Any: ...
3232
```
3333

@@ -53,22 +53,22 @@ For example:
5353
from typing import Any
5454

5555
import strawberry
56-
from strawberry import relay
56+
from strawberry.pagination import connection, Connection
5757

5858

5959
@strawberry.type
60-
class MyType(relay.Node): ...
60+
class MyType: ...
6161

6262

6363
@strawberry.type
6464
class Query:
65-
@relay.connection(relay.Connection[MyType])
65+
@connection(Connection[MyType])
6666
def some_connection(self) -> Iterable[MyType]: ...
6767
```
6868

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

0 commit comments

Comments
 (0)