10000 Pick up the docstrings of hybrid properties by bim9262 · Pull Request #344 · graphql-python/graphene-sqlalchemy · GitHub
[go: up one dir, main page]

Skip to content

Pick up the docstrings of hybrid properties #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def convert_sqlalchemy_hybrid_method(hybrid_prop, resolver, **field_kwargs):
if 'type_' not in field_kwargs:
field_kwargs['type_'] = convert_hybrid_property_return_type(hybrid_prop)

if 'description' not in field_kwargs:
field_kwargs['description'] = getattr(hybrid_prop, "__doc__", None)

return Field(
resolver=resolver,
**field_kwargs
Expand Down
5 changes: 5 additions & 0 deletions graphene_sqlalchemy/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ class Reporter(Base):
articles = relationship("Article", backref="reporter")
favorite_article = relationship("Article", uselist=False)

@hybrid_property
def hybrid_prop_with_doc(self):
"""Docstring test"""
return self.first_name

@hybrid_property
def hybrid_prop(self):
return self.first_name
Expand Down
17 changes: 16 additions & 1 deletion graphene_sqlalchemy/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Meta:
# Composite
"composite_prop",
# Hybrid
"hybrid_prop_with_doc",
"hybrid_prop",
"hybrid_prop_str",
"hybrid_prop_int",
Expand Down Expand Up @@ -150,6 +151,12 @@ class Meta:
# "doc" is ignored by hybrid_property
assert hybrid_prop_list.description is None

# hybrid_prop_with_doc
hybrid_prop_with_doc = ReporterType._meta.fields['hybrid_prop_with_doc']
assert hybrid_prop_with_doc.type == String
# docstring is picked up from hybrid_prop_with_doc
assert hybrid_prop_with_doc.description == "Docstring test"

# relationship
favorite_article_field = ReporterType._meta.fields['favorite_article']
assert isinstance(favorite_article_field, Dynamic)
Expand Down Expand Up @@ -183,6 +190,7 @@ class Meta:
composite_prop = ORMField()

# hybrid_property
hybrid_prop_with_doc = ORMField(description='Overridden')
hybrid_prop = ORMField(description='Overridden')

# relationships
Expand Down Expand Up @@ -210,6 +218,7 @@ class Meta:
"email_v2",
"column_prop",
"composite_prop",
"hybrid_prop_with_doc",
"hybrid_prop",
"favorite_article",
"articles",
Expand Down Expand Up @@ -250,6 +259,11 @@ class Meta:
assert hybrid_prop_field.description == "Overridden"
assert hybrid_prop_field.deprecation_reason is None

hybrid_prop_with_doc_field = ReporterType._meta.fields['hybrid_prop_with_doc']
assert hybrid_prop_with_doc_field.type == String
assert hybrid_prop_with_doc_field.description == "Overridden"
assert hybrid_prop_with_doc_field.deprecation_reason is None

column_prop_field_v2 = ReporterType._meta.fields['column_prop']
assert column_prop_field_v2.type == String
assert column_prop_field_v2.description is None
Expand Down Expand Up @@ -318,6 +332,7 @@ class Meta:
"email",
"favorite_pet_kind",
"composite_prop",
"hybrid_prop_with_doc",
"hybrid_prop",
"hybrid_prop_str",
"hybrid_prop_int",
Expand Down Expand Up @@ -432,7 +447,7 @@ class Meta:

assert issubclass(CustomReporterType, ObjectType)
assert CustomReporterType._meta.model == Reporter
assert len(CustomReporterType._meta.fields) == 16
assert len(CustomReporterType._meta.fields) == 17


# Test Custom SQLAlchemyObjectType with Custom Options
Expand Down
0