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:
Syrus Akbary 2016-02-12 19:23:20 -08:00
commit 9db48c43c1
4 changed files with 7 additions and 7 deletions

View File

@ -117,7 +117,7 @@ class NormalCursorWrapper(object):
'sql': self.db.ops.last_executed_query(
self.cursor, sql, self._quote_params(params)),
'duration': duration,
'raw_sql': sql % params,
'raw_sql': sql,
'params': _params,
'start_time': start_time,
'stop_time': stop_time,

View File

@ -117,7 +117,7 @@ def test_should_query_connection():
class Query(graphene.ObjectType):
all_reporters = DjangoConnectionField(ReporterType)
def resolve_all_reporters_connection(self, *args, **kwargs):
def resolve_all_reporters(self, *args, **kwargs):
return Reporter.objects.all()
query = '''
@ -172,7 +172,7 @@ def test_should_query_connectionfilter():
class Query(graphene.ObjectType):
all_reporters = DjangoFilterConnectionField(ReporterType)
def resolve_all_reporters_connection_filter(self, *args, **kwargs):
def resolve_all_reporters(self, *args, **kwargs):
return Reporter.objects.all()
query = '''

View File

@ -11,6 +11,7 @@ class DjangoConnectionField(ConnectionField):
def __init__(self, *args, **kwargs):
self.on = kwargs.pop('on', False)
kwargs['default'] = kwargs.pop('default', self.get_manager)
return super(DjangoConnectionField, self).__init__(*args, **kwargs)
@property
@ -27,8 +28,6 @@ class DjangoConnectionField(ConnectionField):
return resolved_qs
def from_list(self, connection_type, resolved, args, info):
if resolved is None:
resolved = self.get_manager()
resolved_qs = maybe_queryset(resolved)
qs = self.get_queryset(resolved_qs, args, info)
return super(DjangoConnectionField, self).from_list(connection_type, qs, args, info)

View File

@ -47,8 +47,9 @@ class ObjectType(six.with_metaclass(ObjectTypeMeta, FieldsClassType)):
abstract = True
def __getattr__(self, name):
if name != '_root' and self._root:
return getattr(self._root, name)
if name == '_root':
return
return getattr(self._root, name)
def __init__(self, *args, **kwargs):
signals.pre_init.send(self.__class__, args=args, kwargs=kwargs)