forked from jthorniley/strawberry
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'relay-id' into 0.159.0-plus-relay
- Loading branch information
Showing
32 changed files
with
4,808 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Release type: minor | ||
|
||
Initial relay spec implementation. For information on how to use | ||
it, check out the docs in here: https://strawberry.rocks/docs/guides/relay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: Relay wrong annotation Error | ||
--- | ||
|
||
# Relay wrong annotation error | ||
|
||
## Description | ||
|
||
This error is thrown when a field on a relay connection has a wrong | ||
type annotation. For example, the following code will throw this error: | ||
|
||
```python | ||
from typing import List | ||
|
||
import strawberry | ||
|
||
|
||
@strawberry.type | ||
class NonNodeSubclassType: | ||
... | ||
|
||
|
||
@strawberry.type | ||
class Query: | ||
@strawberry.relay.connection | ||
def some_connection(self) -> int: | ||
... | ||
|
||
@strawberry.relay.connection | ||
def some_other_connection(self) -> List[NonNodeSubclassType]: | ||
... | ||
``` | ||
|
||
This happens because when defining a custom resolver for the connection, | ||
it expects the type annotation to be one of: `Iterable[<NodeType>]`, | ||
`Iterator[<NodeType>]`, `AsyncIterable[<NodeType>]` or `AsyncIterator[<NodeType]` | ||
|
||
## How to fix this error | ||
|
||
You can fix this error by annotating the connection custom resolver with | ||
one of the following possibilities: | ||
|
||
- `Iterable[<NodeType>]` | ||
- `Iterator[<NodeType>]` | ||
- `AsyncIterable[<NodeType>]` | ||
- `AsyncIterator[<NodeType]` | ||
|
||
For example: | ||
|
||
```python | ||
from typing import Iterable, List | ||
|
||
import strawberry | ||
|
||
|
||
@strawberry.type | ||
class NodeSubclassType(strawberry.relay.Node): | ||
... | ||
|
||
|
||
@strawberry.type | ||
class Query: | ||
@strawberry.relay.connection | ||
def some_connection(self) -> List[NodeSubclassType]: | ||
... | ||
|
||
@strawberry.relay.connection | ||
def some_other_connection(self) -> Iterable[NodeSubclassType]: | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
title: Relay wrong annotation Error | ||
--- | ||
|
||
# Relay wrong annotation error | ||
|
||
## Description | ||
|
||
This error is thrown when a field on a relay connection was defined with | ||
a `node_converter` that has the wrong type type annotation. For example, | ||
the following code will throw this error: | ||
|
||
```python | ||
from typing import Iterable | ||
|
||
import strawberry | ||
|
||
|
||
@strawberry.type | ||
class NonNodeSubclassType: | ||
... | ||
|
||
|
||
def node_converter(node_id: str) -> NonNodeSubclassType: | ||
... | ||
|
||
|
||
@strawberry.type | ||
class Query: | ||
@strawberry.relay.connection(NonNodeSubclassType) | ||
def some_connection(self) -> Iterable[str]: | ||
... | ||
``` | ||
|
||
This happens because when defining a `node_converter`, it is expected | ||
to be a function that receives the iterable element as its single argument, | ||
and should return the correct strawberry `Node` implemented type. | ||
|
||
## How to fix this error | ||
|
||
You can fix this error by annotating the `node_converter` function to | ||
return the correct strawberry `Node` implemented type. | ||
|
||
For example: | ||
|
||
```python | ||
from typing import Iterable | ||
|
||
import strawberry | ||
|
||
|
||
@strawberry.type | ||
class NodeSubclassType(strawberry.relay.Node): | ||
... | ||
|
||
|
||
def node_converter(node_id: str) -> NodeSubclassType: | ||
... | ||
|
||
|
||
@strawberry.type | ||
class Query: | ||
@strawberry.relay.connection(node_converter=node_converter) | ||
def some_connection(self) -> Iterable[str]: | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.