mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-26 03:24:07 +03:00
Attempt fix. Breaks tests
This commit is contained in:
parent
67804fdc09
commit
69457cffdf
|
@ -53,8 +53,8 @@ class DjangoConnectionField(ConnectionField):
|
|||
iterable = default_manager
|
||||
iterable = maybe_queryset(iterable)
|
||||
if isinstance(iterable, QuerySet):
|
||||
if iterable is not default_manager:
|
||||
iterable = maybe_queryset(default_manager)
|
||||
if default_manager is not None and iterable is not default_manager:
|
||||
iterable &= maybe_queryset(default_manager)
|
||||
_len = iterable.count()
|
||||
else:
|
||||
_len = len(iterable)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from collections import OrderedDict
|
||||
from functools import partial
|
||||
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
# from graphene.relay import is_node
|
||||
from graphene.types.argument import to_arguments
|
||||
from ..fields import DjangoConnectionField
|
||||
|
@ -44,15 +46,30 @@ class DjangoFilterConnectionField(DjangoConnectionField):
|
|||
def filtering_args(self):
|
||||
return get_filtering_args_from_filterset(self.filterset_class, self.node_type)
|
||||
|
||||
# @staticmethod
|
||||
# def connection_resolver(resolver, connection, default_manager, filterset_class, filtering_args,
|
||||
# root, args, context, info):
|
||||
# filter_kwargs = {k: v for k, v in args.items() if k in filtering_args}
|
||||
# qs = filterset_class(
|
||||
# data=filter_kwargs,
|
||||
# queryset=default_manager.get_queryset()
|
||||
# ).qs
|
||||
# return DjangoConnectionField.connection_resolver(resolver, connection, qs, root, args, context, info)
|
||||
|
||||
@staticmethod
|
||||
def connection_resolver(resolver, connection, default_manager, filterset_class, filtering_args,
|
||||
root, args, context, info):
|
||||
filter_kwargs = {k: v for k, v in args.items() if k in filtering_args}
|
||||
qs = filterset_class(
|
||||
data=filter_kwargs,
|
||||
queryset=default_manager.get_queryset()
|
||||
).qs
|
||||
return DjangoConnectionField.connection_resolver(resolver, connection, qs, root, args, context, info)
|
||||
|
||||
def new_resolver(root, args, context, info):
|
||||
qs = resolver(root, args, context, info)
|
||||
if qs is None or not isinstance(qs, QuerySet):
|
||||
qs = default_manager.get_queryset()
|
||||
qs = filterset_class(data=filter_kwargs, queryset=qs).qs
|
||||
|
||||
return qs
|
||||
|
||||
return DjangoConnectionField.connection_resolver(new_resolver, connection, None, root, args, context, info)
|
||||
|
||||
def get_resolver(self, parent_resolver):
|
||||
return partial(self.connection_resolver, parent_resolver, self.type, self.get_manager(),
|
||||
|
|
|
@ -382,7 +382,7 @@ def test_should_query_node_multiple_filtering():
|
|||
class Meta:
|
||||
model = Article
|
||||
interfaces = (Node, )
|
||||
filter_fields = ('lang', 'tag')
|
||||
filter_fields = ('lang', 'headline')
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
all_reporters = DjangoConnectionField(ReporterType)
|
||||
|
@ -398,24 +398,21 @@ def test_should_query_node_multiple_filtering():
|
|||
pub_date=datetime.date.today(),
|
||||
reporter=r,
|
||||
editor=r,
|
||||
lang='es',
|
||||
tag='one'
|
||||
lang='es'
|
||||
)
|
||||
Article.objects.create(
|
||||
headline='Article Node 2',
|
||||
pub_date=datetime.date.today(),
|
||||
reporter=r,
|
||||
editor=r,
|
||||
lang='en',
|
||||
tag='two'
|
||||
lang='en'
|
||||
)
|
||||
Article.objects.create(
|
||||
headline='Article Node 3',
|
||||
pub_date=datetime.date.today(),
|
||||
reporter=r,
|
||||
editor=r,
|
||||
lang='en',
|
||||
tag='three'
|
||||
lang='en'
|
||||
)
|
||||
|
||||
schema = graphene.Schema(query=Query)
|
||||
|
@ -425,7 +422,7 @@ def test_should_query_node_multiple_filtering():
|
|||
edges {
|
||||
node {
|
||||
id
|
||||
articles(lang: "es", tag: "two") {
|
||||
articles(lang: "es", headline: "Article Node 2") {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
|
|
Loading…
Reference in New Issue
Block a user