mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 09:36:44 +03:00
Added field description based on function doc
This commit is contained in:
parent
23ef63e60e
commit
69de7241ab
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue
Block a user