mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-29 21:13:58 +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)
|
field_type = GraphQLNonNull(field_type)
|
||||||
return field_type
|
return field_type
|
||||||
|
|
||||||
@memoize
|
|
||||||
def internal_type(self, schema):
|
def internal_type(self, schema):
|
||||||
field_type = self.field_type
|
field_type = self.field_type
|
||||||
if isinstance(field_type, Field):
|
if isinstance(field_type, Field):
|
||||||
|
@ -127,8 +126,11 @@ class Field(object):
|
||||||
if not internal_type:
|
if not internal_type:
|
||||||
raise Exception("Internal type for field %s is None" % self)
|
raise Exception("Internal type for field %s is None" % self)
|
||||||
|
|
||||||
|
description = self.description
|
||||||
resolve_fn = self.get_resolve_fn()
|
resolve_fn = self.get_resolve_fn()
|
||||||
if resolve_fn:
|
if resolve_fn:
|
||||||
|
description = resolve_fn.__doc__ or description
|
||||||
|
|
||||||
@wraps(resolve_fn)
|
@wraps(resolve_fn)
|
||||||
def resolver(*args):
|
def resolver(*args):
|
||||||
return self.resolve(*args)
|
return self.resolve(*args)
|
||||||
|
@ -136,7 +138,7 @@ class Field(object):
|
||||||
resolver = self.resolve
|
resolver = self.resolve
|
||||||
return GraphQLField(
|
return GraphQLField(
|
||||||
internal_type,
|
internal_type,
|
||||||
description=self.description,
|
description=description,
|
||||||
args=self.args,
|
args=self.args,
|
||||||
resolver=resolver,
|
resolver=resolver,
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,12 +24,10 @@ from graphene.core.types import ObjectType
|
||||||
class ObjectType(object):
|
class ObjectType(object):
|
||||||
_meta = Options()
|
_meta = Options()
|
||||||
|
|
||||||
def resolve(self, *args, **kwargs):
|
def resolve_customdoc(self, *args, **kwargs):
|
||||||
|
'''Resolver documentation'''
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def can_resolve(self, *args):
|
|
||||||
return True
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "ObjectType"
|
return "ObjectType"
|
||||||
|
|
||||||
|
@ -172,3 +170,10 @@ def test_field_repr_contributed():
|
||||||
f = StringField()
|
f = StringField()
|
||||||
f.contribute_to_class(ot, 'field_name')
|
f.contribute_to_class(ot, 'field_name')
|
||||||
assert repr(f) == "<graphene.core.fields.StringField: 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