|
2 | 2 |
|
3 | 3 | import six
|
4 | 4 | from sqlalchemy.inspection import inspect as sqlalchemyinspect
|
| 5 | +from sqlalchemy.ext.hybrid import hybrid_property |
5 | 6 | from sqlalchemy.orm.exc import NoResultFound
|
6 | 7 |
|
7 | 8 | from graphene import Field, ObjectType
|
|
13 | 14 |
|
14 | 15 | from .converter import (convert_sqlalchemy_column,
|
15 | 16 | convert_sqlalchemy_composite,
|
16 |
| - convert_sqlalchemy_relationship) |
| 17 | + convert_sqlalchemy_relationship, |
| 18 | + convert_sqlalchemy_hybrid_method) |
17 | 19 | from .registry import Registry, get_global_registry
|
18 | 20 | from .utils import get_query, is_mapped
|
19 | 21 |
|
@@ -47,6 +49,24 @@ def construct_fields(options):
|
47 | 49 | converted_composite = convert_sqlalchemy_composite(composite, options.registry)
|
48 | 50 | fields[name] = converted_composite
|
49 | 51 |
|
| 52 | + for hybrid_item in inspected_model.all_orm_descriptors: |
| 53 | + |
| 54 | + if type(hybrid_item) == hybrid_property: |
| 55 | + name = hybrid_item.__name__ |
| 56 | + |
| 57 | + is_not_in_only = only_fields and name not in only_fields |
| 58 | + is_already_created = name in options.fields |
| 59 | + is_excluded = name in exclude_fields or is_already_created |
| 60 | + |
| 61 | + if is_not_in_only or is_excluded: |
| 62 | + # We skip this field if we specify only_fields and is not |
| 63 | + # in there. Or when we excldue this field in exclude_fields |
| 64 | + |
| 65 | + continue |
| 66 | + converted_hybrid_property = convert_sqlalchemy_hybrid_method( |
| 67 | + hybrid_item) |
| 68 | + fields[name] = converted_hybrid_property |
| 69 | + |
50 | 70 | # Get all the columns for the relationships on the model
|
51 | 71 | for relationship in inspected_model.relationships:
|
52 | 72 | is_not_in_only = only_fields and relationship.key not in only_fields
|
|
0 commit comments