Restore compatibility with graphql-relay-py v3

Add adpaters for the PageInfo and Connection args.
This commit is contained in:
Christoph Zwerschke 2019-07-12 21:02:00 +02:00 committed by Mel van Londen
parent 9594bc616c
commit 8b07dbac9b
2 changed files with 23 additions and 5 deletions

View File

@ -2,7 +2,7 @@ import re
from collections import Iterable from collections import Iterable
from functools import partial 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 import Boolean, Enum, Int, Interface, List, NonNull, Scalar, String, Union
from ..types.field import Field 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): class ConnectionOptions(ObjectTypeOptions):
node = None 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): class IterableConnectionField(Field):
def __init__(self, type, *args, **kwargs): def __init__(self, type, *args, **kwargs):
kwargs.setdefault("before", String()) kwargs.setdefault("before", String())
@ -138,12 +152,12 @@ class IterableConnectionField(Field):
"Resolved value from the connection field has to be iterable or instance of {}. " "Resolved value from the connection field has to be iterable or instance of {}. "
'Received "{}"' 'Received "{}"'
).format(connection_type, resolved) ).format(connection_type, resolved)
connection = connection_from_list( connection = connection_from_array(
resolved, resolved,
args, args,
connection_type=connection_type, connection_type=partial(connection_adapter, connection_type),
edge_type=connection_type.Edge, edge_type=connection_type.Edge,
pageinfo_type=PageInfo, page_info_type=page_info_adapter,
) )
connection.iterable = resolved connection.iterable = resolved
return connection return connection

View File

@ -79,7 +79,11 @@ setup(
], ],
keywords="api graphql protocol rest relay graphene", keywords="api graphql protocol rest relay graphene",
packages=find_packages(exclude=["tests", "tests.*", "examples"]), 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, tests_require=tests_require,
extras_require={ extras_require={
"test": tests_require, "test": tests_require,