Improved default field getter and improved relay connection resolver

This commit is contained in:
Syrus Akbary 2016-01-02 21:04:27 +01:00
parent 39a4fe20b3
commit 33c58f6cfa
2 changed files with 13 additions and 3 deletions

View File

@ -51,6 +51,16 @@ class Field(NamedType, OrderedType):
def resolver(self): def resolver(self):
return self.resolver_fn or self.get_resolver_fn() 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): def get_resolver_fn(self):
resolve_fn_name = 'resolve_%s' % self.attname resolve_fn_name = 'resolve_%s' % self.attname
if hasattr(self.object_type, resolve_fn_name): if hasattr(self.object_type, resolve_fn_name):

View File

@ -23,15 +23,15 @@ class ConnectionField(Field):
self.connection_type = connection_type self.connection_type = connection_type
self.edge_type = edge_type self.edge_type = edge_type
def wrap_resolved(self, value, instance, args, info):
return value
def resolver(self, instance, args, info): def resolver(self, instance, args, info):
schema = info.schema.graphene_schema schema = info.schema.graphene_schema
connection_type = self.get_type(schema) connection_type = self.get_type(schema)
resolved = super(ConnectionField, self).resolver(instance, args, info) resolved = super(ConnectionField, self).resolver(instance, args, info)
if isinstance(resolved, connection_type): if isinstance(resolved, connection_type):
return resolved 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) return connection_type.from_list(resolved, args, info)
def get_connection_type(self, node): def get_connection_type(self, node):