Skip to content

Commit

Permalink
feat: Allow connection to be used without relay for generic cursor pa…
Browse files Browse the repository at this point in the history
…gination
  • Loading branch information
bellini666 committed Oct 12, 2024
1 parent d504428 commit ddcc952
Show file tree
Hide file tree
Showing 23 changed files with 1,620 additions and 1,774 deletions.
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).
File renamed without changes.
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

0 comments on commit ddcc952

Please sign in to comment.