Added field description based on function doc

This commit is contained in:
Syrus Akbary 2015-10-25 19:48:22 -07:00
parent 23ef63e60e
commit 69de7241ab
2 changed files with 13 additions and 6 deletions

View File

@ -91,7 +91,6 @@ class Field(object):
field_type = GraphQLNonNull(field_type)
return field_type
@memoize
def internal_type(self, schema):
field_type = self.field_type
if isinstance(field_type, Field):
@ -127,8 +126,11 @@ class Field(object):
if not internal_type:
raise Exception("Internal type for field %s is None" % self)
description = self.description
resolve_fn = self.get_resolve_fn()
if resolve_fn:
description = resolve_fn.__doc__ or description
@wraps(resolve_fn)
def resolver(*args):
return self.resolve(*args)
@ -136,7 +138,7 @@ class Field(object):
resolver = self.resolve
return GraphQLField(
internal_type,
description=self.description,
description=description,
args=self.args,
resolver=resolver,
)

View File

@ -24,12 +24,10 @@ from graphene.core.types import ObjectType
class ObjectType(object):
_meta = Options()
def resolve(self, *args, **kwargs):
def resolve_customdoc(self, *args, **kwargs):
'''Resolver documentation'''
return None
def can_resolve(self, *args):
return True
def __str__(self):
return "ObjectType"
@ -172,3 +170,10 @@ def test_field_repr_contributed():
f = StringField()
f.contribute_to_class(ot, 'field_name')
assert repr(f) == "<graphene.core.fields.StringField: field_name>"
def test_field_resolve_objecttype_cos():
f = StringField()
f.contribute_to_class(ot, 'customdoc')
field = f.internal_field(schema)
assert field.description == 'Resolver documentation'