mirror of
https://github.com/graphql-python/graphene.git
synced 2025-09-21 11:22:33 +03:00
Restore compatibility with graphql-relay-py v3
Add adpaters for the PageInfo and Connection args.
This commit is contained in:
parent
9594bc616c
commit
8b07dbac9b
|
@ -2,7 +2,7 @@ import re
|
|||
from collections import Iterable
|
||||
from functools import partial
|
||||
|
||||
from graphql_relay import connection_from_list
|
||||
from graphql_relay import connection_from_array
|
||||
|
||||
from ..types import Boolean, Enum, Int, Interface, List, NonNull, Scalar, String, Union
|
||||
from ..types.field import Field
|
||||
|
@ -41,6 +41,14 @@ class PageInfo(ObjectType):
|
|||
)
|
||||
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
def page_info_adapter(startCursor, endCursor, hasPreviousPage, hasNextPage):
|
||||
"""Adapter for creating PageInfo instances"""
|
||||
return PageInfo(
|
||||
start_cursor=startCursor, end_cursor=endCursor,
|
||||
has_previous_page=hasPreviousPage, has_next_page=hasNextPage)
|
||||
|
||||
|
||||
class ConnectionOptions(ObjectTypeOptions):
|
||||
node = None
|
||||
|
||||
|
@ -103,6 +111,12 @@ class Connection(ObjectType):
|
|||
)
|
||||
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
def connection_adapter(cls, edges, pageInfo):
|
||||
"""Adapter for creating Connection instances"""
|
||||
return cls(edges=edges, page_info=pageInfo)
|
||||
|
||||
|
||||
class IterableConnectionField(Field):
|
||||
def __init__(self, type, *args, **kwargs):
|
||||
kwargs.setdefault("before", String())
|
||||
|
@ -138,12 +152,12 @@ class IterableConnectionField(Field):
|
|||
"Resolved value from the connection field has to be iterable or instance of {}. "
|
||||
'Received "{}"'
|
||||
).format(connection_type, resolved)
|
||||
connection = connection_from_list(
|
||||
connection = connection_from_array(
|
||||
resolved,
|
||||
args,
|
||||
connection_type=connection_type,
|
||||
connection_type=partial(connection_adapter, connection_type),
|
||||
edge_type=connection_type.Edge,
|
||||
pageinfo_type=PageInfo,
|
||||
page_info_type=page_info_adapter,
|
||||
)
|
||||
connection.iterable = resolved
|
||||
return connection
|
||||
|
|
6
setup.py
6
setup.py
|
@ -79,7 +79,11 @@ setup(
|
|||
],
|
||||
keywords="api graphql protocol rest relay graphene",
|
||||
packages=find_packages(exclude=["tests", "tests.*", "examples"]),
|
||||
install_requires=["graphql-core-next~=1.0.5", "aniso8601~=6.0.0"],
|
||||
install_requires=[
|
||||
"graphql-core-next>=1.1.0b0,<2",
|
||||
"graphql-relay>=3.0.0a0,<4",
|
||||
"aniso8601~=6.0.0"
|
||||
],
|
||||
tests_require=tests_require,
|
||||
extras_require={
|
||||
"test": tests_require,
|
||||
|
|
Loading…
Reference in New Issue
Block a user