From 33c58f6cfa14771e7d90fa6d6a42eb590b76e5f4 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sat, 2 Jan 2016 21:04:27 +0100 Subject: [PATCH] Improved default field getter and improved relay connection resolver --- graphene/core/types/field.py | 10 ++++++++++ graphene/relay/fields.py | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/graphene/core/types/field.py b/graphene/core/types/field.py index 6cbfff96..2d96f1d3 100644 --- a/graphene/core/types/field.py +++ b/graphene/core/types/field.py @@ -51,6 +51,16 @@ class Field(NamedType, OrderedType): def resolver(self): return self.resolver_fn or self.get_resolver_fn() + @property + def default(self): + if callable(self._default): + return self._default() + return self._default + + @default.setter + def default(self, value): + self._default = value + def get_resolver_fn(self): resolve_fn_name = 'resolve_%s' % self.attname if hasattr(self.object_type, resolve_fn_name): diff --git a/graphene/relay/fields.py b/graphene/relay/fields.py index dc8c4973..aa446083 100644 --- a/graphene/relay/fields.py +++ b/graphene/relay/fields.py @@ -23,15 +23,15 @@ class ConnectionField(Field): self.connection_type = connection_type self.edge_type = edge_type - def wrap_resolved(self, value, instance, args, info): - return value - def resolver(self, instance, args, info): schema = info.schema.graphene_schema connection_type = self.get_type(schema) resolved = super(ConnectionField, self).resolver(instance, args, info) if isinstance(resolved, connection_type): return resolved + return self.from_list(connection_type, resolved, args, info) + + def from_list(self, connection_type, resolved, args, info): return connection_type.from_list(resolved, args, info) def get_connection_type(self, node):