-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix specialized connection aliases missing filters/ordering
- Loading branch information
1 parent
9454e99
commit 9233a5c
Showing
9 changed files
with
285 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
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,24 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
import strawberry | ||
from strawberry import relay | ||
from typing_extensions import Annotated, TypeAlias | ||
|
||
import strawberry_django | ||
from strawberry_django.relay import ListConnectionWithTotalCount | ||
|
||
from .models import RelayAuthor | ||
|
||
if TYPE_CHECKING: | ||
from .b import BookConnection | ||
|
||
|
||
@strawberry_django.type(RelayAuthor) | ||
class AuthorType(relay.Node): | ||
name: str | ||
books: Annotated["BookConnection", strawberry.lazy("tests.relay.lazy.b")] = ( | ||
strawberry_django.connection() | ||
) | ||
|
||
|
||
AuthorConnection: TypeAlias = ListConnectionWithTotalCount[AuthorType] |
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,32 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
import strawberry | ||
from strawberry import relay | ||
from typing_extensions import Annotated, TypeAlias | ||
|
||
import strawberry_django | ||
from strawberry_django.relay import ListConnectionWithTotalCount | ||
|
||
from .models import RelayBook | ||
|
||
if TYPE_CHECKING: | ||
from .a import AuthorType | ||
|
||
|
||
@strawberry_django.filter(RelayBook) | ||
class BookFilter: | ||
name: str | ||
|
||
|
||
@strawberry_django.order(RelayBook) | ||
class BookOrder: | ||
name: str | ||
|
||
|
||
@strawberry_django.type(RelayBook, filters=BookFilter, order=BookOrder) | ||
class BookType(relay.Node): | ||
name: str | ||
author: Annotated["AuthorType", strawberry.lazy("tests.relay.lazy.a")] | ||
|
||
|
||
BookConnection: TypeAlias = ListConnectionWithTotalCount[BookType] |
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,14 @@ | ||
from django.db import models | ||
|
||
|
||
class RelayAuthor(models.Model): | ||
name = models.CharField(max_length=100) | ||
|
||
|
||
class RelayBook(models.Model): | ||
title = models.CharField(max_length=100) | ||
author = models.ForeignKey( | ||
RelayAuthor, | ||
on_delete=models.CASCADE, | ||
related_name="books", | ||
) |
169 changes: 169 additions & 0 deletions
169
tests/relay/lazy/snapshots/test_lazy_annotations/test_schema/authors_and_books_schema.gql
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,169 @@ | ||
type AuthorType implements Node { | ||
"""The Globally Unique ID of this object""" | ||
id: GlobalID! | ||
name: String! | ||
books( | ||
filters: BookFilter | ||
order: BookOrder | ||
|
||
"""Returns the items in the list that come before the specified cursor.""" | ||
before: String = null | ||
|
||
"""Returns the items in the list that come after the specified cursor.""" | ||
after: String = null | ||
|
||
"""Returns the first n items from the list.""" | ||
first: Int = null | ||
|
||
"""Returns the items in the list that come after the specified cursor.""" | ||
last: Int = null | ||
): BookTypeConnection! | ||
} | ||
|
||
"""A connection to a list of items.""" | ||
type AuthorTypeConnection { | ||
"""Pagination data for this connection""" | ||
pageInfo: PageInfo! | ||
|
||
"""Contains the nodes in this connection""" | ||
edges: [AuthorTypeEdge!]! | ||
|
||
"""Total quantity of existing nodes.""" | ||
totalCount: Int | ||
} | ||
|
||
"""An edge in a connection.""" | ||
type AuthorTypeEdge { | ||
"""A cursor for use in pagination""" | ||
cursor: String! | ||
|
||
"""The item at the end of the edge""" | ||
node: AuthorType! | ||
} | ||
|
||
input BookFilter { | ||
name: String! | ||
AND: BookFilter | ||
OR: BookFilter | ||
NOT: BookFilter | ||
DISTINCT: Boolean | ||
} | ||
|
||
input BookOrder { | ||
name: String | ||
} | ||
|
||
type BookType implements Node { | ||
"""The Globally Unique ID of this object""" | ||
id: GlobalID! | ||
name: String! | ||
author: AuthorType! | ||
} | ||
|
||
"""A connection to a list of items.""" | ||
type BookTypeConnection { | ||
"""Pagination data for this connection""" | ||
pageInfo: PageInfo! | ||
|
||
"""Contains the nodes in this connection""" | ||
edges: [BookTypeEdge!]! | ||
|
||
"""Total quantity of existing nodes.""" | ||
totalCount: Int | ||
} | ||
|
||
"""An edge in a connection.""" | ||
type BookTypeEdge { | ||
"""A cursor for use in pagination""" | ||
cursor: String! | ||
|
||
"""The item at the end of the edge""" | ||
node: BookType! | ||
} | ||
|
||
""" | ||
The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID. | ||
""" | ||
scalar GlobalID @specifiedBy(url: "https://relay.dev/graphql/objectidentification.htm") | ||
|
||
"""An object with a Globally Unique ID""" | ||
interface Node { | ||
"""The Globally Unique ID of this object""" | ||
id: GlobalID! | ||
} | ||
|
||
"""Information to aid in pagination.""" | ||
type PageInfo { | ||
"""When paginating forwards, are there more items?""" | ||
hasNextPage: Boolean! | ||
|
||
"""When paginating backwards, are there more items?""" | ||
hasPreviousPage: Boolean! | ||
|
||
"""When paginating backwards, the cursor to continue.""" | ||
startCursor: String | ||
|
||
"""When paginating forwards, the cursor to continue.""" | ||
endCursor: String | ||
} | ||
|
||
type Query { | ||
booksConn( | ||
filters: BookFilter | ||
order: BookOrder | ||
|
||
"""Returns the items in the list that come before the specified cursor.""" | ||
before: String = null | ||
|
||
"""Returns the items in the list that come after the specified cursor.""" | ||
after: String = null | ||
|
||
"""Returns the first n items from the list.""" | ||
first: Int = null | ||
|
||
"""Returns the items in the list that come after the specified cursor.""" | ||
last: Int = null | ||
): BookTypeConnection! | ||
booksConn2( | ||
filters: BookFilter | ||
order: BookOrder | ||
|
||
"""Returns the items in the list that come before the specified cursor.""" | ||
before: String = null | ||
|
||
"""Returns the items in the list that come after the specified cursor.""" | ||
after: String = null | ||
|
||
"""Returns the first n items from the list.""" | ||
first: Int = null | ||
|
||
"""Returns the items in the list that come after the specified cursor.""" | ||
last: Int = null | ||
): BookTypeConnection! | ||
authorsConn( | ||
"""Returns the items in the list that come before the specified cursor.""" | ||
before: String = null | ||
|
||
"""Returns the items in the list that come after the specified cursor.""" | ||
after: String = null | ||
|
||
"""Returns the first n items from the list.""" | ||
first: Int = null | ||
|
||
"""Returns the items in the list that come after the specified cursor.""" | ||
last: Int = null | ||
): AuthorTypeConnection! | ||
authorsConn2( | ||
"""Returns the items in the list that come before the specified cursor.""" | ||
before: String = null | ||
|
||
"""Returns the items in the list that come after the specified cursor.""" | ||
after: String = null | ||
|
||
"""Returns the first n items from the list.""" | ||
first: Int = null | ||
|
||
"""Returns the items in the list that come after the specified cursor.""" | ||
last: Int = null | ||
): AuthorTypeConnection! | ||
} |
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,28 @@ | ||
import pathlib | ||
|
||
import strawberry | ||
from pytest_snapshot.plugin import Snapshot | ||
|
||
import strawberry_django | ||
from strawberry_django.relay import ListConnectionWithTotalCount | ||
|
||
from .a import AuthorConnection, AuthorType | ||
from .b import BookConnection, BookType | ||
|
||
SNAPSHOTS_DIR = pathlib.Path(__file__).parent / "snapshots" | ||
|
||
|
||
def test_schema(snapshot: Snapshot): | ||
@strawberry.type | ||
class Query: | ||
books_conn: BookConnection = strawberry_django.connection() | ||
books_conn2: ListConnectionWithTotalCount[BookType] = ( | ||
strawberry_django.connection() | ||
) | ||
authors_conn: AuthorConnection = strawberry_django.connection() | ||
authors_conn2: ListConnectionWithTotalCount[AuthorType] = ( | ||
strawberry_django.connection() | ||
) | ||
|
||
schema = strawberry.Schema(query=Query) | ||
snapshot.assert_match(str(schema), "authors_and_books_schema.gql") |