mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 20:54:16 +03:00
Django Connection PageInfo type solved. Fixed #274
This commit is contained in:
parent
92dbba91b7
commit
907b34676d
|
@ -1,7 +1,7 @@
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from graphene.relay import ConnectionField
|
from graphene.relay import ConnectionField, PageInfo
|
||||||
from graphql_relay.connection.arrayconnection import connection_from_list_slice
|
from graphql_relay.connection.arrayconnection import connection_from_list_slice
|
||||||
from .utils import maybe_queryset, DJANGO_FILTER_INSTALLED
|
from .utils import maybe_queryset, DJANGO_FILTER_INSTALLED
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ class DjangoConnectionField(ConnectionField):
|
||||||
list_slice_length=_len,
|
list_slice_length=_len,
|
||||||
connection_type=connection,
|
connection_type=connection,
|
||||||
edge_type=connection.Edge,
|
edge_type=connection.Edge,
|
||||||
|
pageinfo_type=PageInfo,
|
||||||
)
|
)
|
||||||
connection.iterable = iterable
|
connection.iterable = iterable
|
||||||
connection.length = _len
|
connection.length = _len
|
||||||
|
|
|
@ -9,6 +9,7 @@ from graphene.relay import Node
|
||||||
|
|
||||||
from ..compat import MissingType, RangeField
|
from ..compat import MissingType, RangeField
|
||||||
from ..types import DjangoObjectType
|
from ..types import DjangoObjectType
|
||||||
|
from ..fields import DjangoConnectionField
|
||||||
from ..registry import reset_global_registry, get_global_registry
|
from ..registry import reset_global_registry, get_global_registry
|
||||||
from .models import Article, Reporter
|
from .models import Article, Reporter
|
||||||
|
|
||||||
|
@ -204,3 +205,48 @@ def test_should_node():
|
||||||
result = schema.execute(query)
|
result = schema.execute(query)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_query_connectionfields():
|
||||||
|
class ReporterType(DjangoObjectType):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Reporter
|
||||||
|
interfaces = (Node, )
|
||||||
|
only_fields = ('articles', )
|
||||||
|
|
||||||
|
class Query(graphene.ObjectType):
|
||||||
|
all_reporters = DjangoConnectionField(ReporterType)
|
||||||
|
|
||||||
|
def resolve_all_reporters(self, args, context, info):
|
||||||
|
return [Reporter(id=1)]
|
||||||
|
|
||||||
|
schema = graphene.Schema(query=Query)
|
||||||
|
query = '''
|
||||||
|
query ReporterConnectionQuery {
|
||||||
|
allReporters {
|
||||||
|
pageInfo {
|
||||||
|
hasNextPage
|
||||||
|
}
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
result = schema.execute(query)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {
|
||||||
|
'allReporters': {
|
||||||
|
'pageInfo': {
|
||||||
|
'hasNextPage': False,
|
||||||
|
},
|
||||||
|
'edges': [{
|
||||||
|
'node': {
|
||||||
|
'id': 'UmVwb3J0ZXJUeXBlOjE='
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user