|
25 | 25 | )
|
26 | 26 | from .utils import wrap_select_func
|
27 | 27 | from ..converter import (
|
| 28 | + convert_sqlalchemy_association_proxy, |
28 | 29 | convert_sqlalchemy_column,
|
29 | 30 | convert_sqlalchemy_composite,
|
30 | 31 | convert_sqlalchemy_hybrid_method,
|
|
41 | 42 | CompositeFullName,
|
42 | 43 | CustomColumnModel,
|
43 | 44 | Pet,
|
| 45 | + ProxiedReporter, |
44 | 46 | Reporter,
|
45 | 47 | ShoppingCart,
|
46 | 48 | ShoppingCartItem,
|
@@ -650,6 +652,64 @@ class Meta:
|
650 | 652 | assert graphene_type.type == A
|
651 | 653 |
|
652 | 654 |
|
| 655 | +def test_should_convert_association_proxy(): |
| 656 | + class ReporterType(SQLAlchemyObjectType): |
| 657 | + class Meta: |
| 658 | + model = Reporter |
| 659 | + |
| 660 | + class ArticleType(SQLAlchemyObjectType): |
| 661 | + class Meta: |
| 662 | + model = Article |
| 663 | + |
| 664 | + field = convert_sqlalchemy_association_proxy( |
| 665 | + Reporter, |
| 666 | + Reporter.headlines, |
| 667 | + ReporterType, |
| 668 | + get_global_registry(), |
| 669 | + default_connection_field_factory, |
| 670 | + True, |
| 671 | + mock_resolver, |
| 672 | + ) |
| 673 | + assert isinstance(field, graphene.Dynamic) |
| 674 | + assert isinstance(field.get_type().type, graphene.List) |
| 675 | + assert field.get_type().type.of_type == graphene.String |
| 676 | + |
| 677 | + dynamic_field = convert_sqlalchemy_association_proxy( |
| 678 | + Article, |
| 679 | + Article.recommended_reads, |
| 680 | + ArticleType, |
| 681 | + get_global_registry(), |
| 682 | + default_connection_field_factory, |
| 683 | + True, |
| 684 | + mock_resolver, |
| 685 | + ) |
| 686 | + dynamic_field_type = dynamic_field.get_type().type |
| 687 | + assert isinstance(dynamic_field, graphene.Dynamic) |
| 688 | + assert isinstance(dynamic_field_type, graphene.NonNull) |
| 689 | + assert isinstance(dynamic_field_type.of_type, graphene.List) |
| 690 | + assert isinstance(dynamic_field_type.of_type.of_type, graphene.NonNull) |
| 691 | + assert dynamic_field_type.of_type.of_type.of_type == ArticleType |
| 692 | + |
| 693 | + |
| 694 | +def test_should_throw_error_association_proxy_unsupported_target(): |
| 695 | + class ProxiedReporterType(SQLAlchemyObjectType): |
| 696 | + class Meta: |
| 697 | + model = ProxiedReporter |
| 698 | + |
| 699 | + field = convert_sqlalchemy_association_proxy( |
| 700 | + ProxiedReporter, |
| 701 | + ProxiedReporter.composite_prop, |
| 702 | + ProxiedReporterType, |
| 703 | + get_global_registry(), |
| 704 | + default_connection_field_factory, |
| 705 | + True, |
| 706 | + mock_resolver, |
| 707 | + ) |
| 708 | + |
| 709 | + with pytest.raises(TypeError): |
| 710 | + field.get_type() |
| 711 | + |
| 712 | + |
653 | 713 | def test_should_postgresql_uuid_convert():
|
654 | 714 | assert get_field(postgresql.UUID()).type == graphene.UUID
|
655 | 715 |
|
|
0 commit comments