|
1 | 1 | import datetime
|
| 2 | +import enum |
2 | 3 | import typing
|
| 4 | +import warnings |
3 | 5 | from decimal import Decimal
|
4 | 6 | from functools import singledispatch
|
5 | 7 | from typing import Any
|
|
18 | 20 | default_connection_field_factory)
|
19 | 21 | from .registry import get_global_registry
|
20 | 22 | from .resolvers import get_attr_resolver, get_custom_resolver
|
21 |
| -from .utils import singledispatchbymatchfunction, value_equals |
| 23 | +from .utils import (singledispatchbymatchfunction, value_equals, |
| 24 | + value_is_subclass) |
22 | 25 |
|
23 | 26 | try:
|
24 | 27 | from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType, TSVectorType
|
@@ -271,7 +274,13 @@ def convert_hybrid_property_return_type_inner(arg: Any):
|
271 | 274 | existing_graphql_type = get_global_registry().get_type_for_model(arg)
|
272 | 275 | if existing_graphql_type:
|
273 | 276 | return existing_graphql_type
|
274 |
| - raise Exception(f"I don't know how to generate a GraphQL type out of a \"{arg}\" type") |
| 277 | + |
| 278 | + # No valid type found, warn and fall back to graphene.String |
| 279 | + warnings.warn( |
| 280 | + (f"I don't know how to generate a GraphQL type out of a \"{arg}\" type." |
| 281 | + "Falling back to \"graphene.String\"") |
| 282 | + ) |
| 283 | + return String |
275 | 284 |
|
276 | 285 |
|
277 | 286 | @convert_hybrid_property_return_type_inner.register(value_equals(str))
|
@@ -317,6 +326,11 @@ def convert_hybrid_property_return_type_inner_time(arg):
|
317 | 326 | return Time
|
318 | 327 |
|
319 | 328 |
|
| 329 | +@convert_hybrid_property_return_type_inner.register(value_is_subclass(enum.Enum)) |
| 330 | +def convert_hybrid_property_return_type_inner_enum(arg): |
| 331 | + return Enum.from_enum(arg) |
| 332 | + |
| 333 | + |
320 | 334 | @convert_hybrid_property_return_type_inner.register(lambda x: getattr(x, '__origin__', None) in [list, typing.List])
|
321 | 335 | def convert_hybrid_property_return_type_inner_list(arg):
|
322 | 336 | # type is either list[T] or List[T], generic argument at __args__[0]
|
|
0 commit comments