mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-14 05:36:45 +03:00
Merge pull request #118 from graphql-python/features/default-django-connection
Fix Connections and Filters for use a manager as default value
This commit is contained in:
commit
9db48c43c1
|
@ -117,7 +117,7 @@ class NormalCursorWrapper(object):
|
||||||
'sql': self.db.ops.last_executed_query(
|
'sql': self.db.ops.last_executed_query(
|
||||||
self.cursor, sql, self._quote_params(params)),
|
self.cursor, sql, self._quote_params(params)),
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'raw_sql': sql % params,
|
'raw_sql': sql,
|
||||||
'params': _params,
|
'params': _params,
|
||||||
'start_time': start_time,
|
'start_time': start_time,
|
||||||
'stop_time': stop_time,
|
'stop_time': stop_time,
|
||||||
|
|
|
@ -117,7 +117,7 @@ def test_should_query_connection():
|
||||||
class Query(graphene.ObjectType):
|
class Query(graphene.ObjectType):
|
||||||
all_reporters = DjangoConnectionField(ReporterType)
|
all_reporters = DjangoConnectionField(ReporterType)
|
||||||
|
|
||||||
def resolve_all_reporters_connection(self, *args, **kwargs):
|
def resolve_all_reporters(self, *args, **kwargs):
|
||||||
return Reporter.objects.all()
|
return Reporter.objects.all()
|
||||||
|
|
||||||
query = '''
|
query = '''
|
||||||
|
@ -172,7 +172,7 @@ def test_should_query_connectionfilter():
|
||||||
class Query(graphene.ObjectType):
|
class Query(graphene.ObjectType):
|
||||||
all_reporters = DjangoFilterConnectionField(ReporterType)
|
all_reporters = DjangoFilterConnectionField(ReporterType)
|
||||||
|
|
||||||
def resolve_all_reporters_connection_filter(self, *args, **kwargs):
|
def resolve_all_reporters(self, *args, **kwargs):
|
||||||
return Reporter.objects.all()
|
return Reporter.objects.all()
|
||||||
|
|
||||||
query = '''
|
query = '''
|
||||||
|
|
|
@ -11,6 +11,7 @@ class DjangoConnectionField(ConnectionField):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.on = kwargs.pop('on', False)
|
self.on = kwargs.pop('on', False)
|
||||||
|
kwargs['default'] = kwargs.pop('default', self.get_manager)
|
||||||
return super(DjangoConnectionField, self).__init__(*args, **kwargs)
|
return super(DjangoConnectionField, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -27,8 +28,6 @@ class DjangoConnectionField(ConnectionField):
|
||||||
return resolved_qs
|
return resolved_qs
|
||||||
|
|
||||||
def from_list(self, connection_type, resolved, args, info):
|
def from_list(self, connection_type, resolved, args, info):
|
||||||
if resolved is None:
|
|
||||||
resolved = self.get_manager()
|
|
||||||
resolved_qs = maybe_queryset(resolved)
|
resolved_qs = maybe_queryset(resolved)
|
||||||
qs = self.get_queryset(resolved_qs, args, info)
|
qs = self.get_queryset(resolved_qs, args, info)
|
||||||
return super(DjangoConnectionField, self).from_list(connection_type, qs, args, info)
|
return super(DjangoConnectionField, self).from_list(connection_type, qs, args, info)
|
||||||
|
|
|
@ -47,7 +47,8 @@ class ObjectType(six.with_metaclass(ObjectTypeMeta, FieldsClassType)):
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name != '_root' and self._root:
|
if name == '_root':
|
||||||
|
return
|
||||||
return getattr(self._root, name)
|
return getattr(self._root, name)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user