mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-04 09:57:41 +03:00 
			
		
		
		
	sqla: convert sqla-utils ScalarListType
This commit is contained in:
		
							parent
							
								
									ceffc4de69
								
							
						
					
					
						commit
						77d68689ba
					
				| 
						 | 
				
			
			@ -9,11 +9,14 @@ from graphene.types.json import JSONString
 | 
			
		|||
from .fields import SQLAlchemyConnectionField
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    from sqlalchemy_utils.types.choice import ChoiceType
 | 
			
		||||
    from sqlalchemy_utils import ChoiceType, ScalarListType
 | 
			
		||||
except ImportError:
 | 
			
		||||
    class ChoiceType(object):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    class ScalarListType(object):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def convert_sqlalchemy_relationship(relationship, registry):
 | 
			
		||||
    direction = relationship.direction
 | 
			
		||||
| 
						 | 
				
			
			@ -85,6 +88,11 @@ def convert_column_to_enum(type, column, registry=None):
 | 
			
		|||
    return Enum(name, type.choices, description=column.doc)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@convert_sqlalchemy_type.register(ScalarListType)
 | 
			
		||||
def convert_scalar_list_to_list(type, column, registry=None):
 | 
			
		||||
    return List(String, description=column.doc)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@convert_sqlalchemy_type.register(postgresql.ARRAY)
 | 
			
		||||
def convert_postgres_array_to_list(type, column, registry=None):
 | 
			
		||||
    graphene_type = convert_sqlalchemy_type(column.type.item_type, column)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
from py.test import raises
 | 
			
		||||
from sqlalchemy import Column, Table, types
 | 
			
		||||
from sqlalchemy.ext.declarative import declarative_base
 | 
			
		||||
from sqlalchemy_utils.types.choice import ChoiceType
 | 
			
		||||
from sqlalchemy_utils import ChoiceType, ScalarListType
 | 
			
		||||
from sqlalchemy.dialects import postgresql
 | 
			
		||||
 | 
			
		||||
import graphene
 | 
			
		||||
| 
						 | 
				
			
			@ -108,6 +108,10 @@ def test_should_choice_convert_enum():
 | 
			
		|||
    assert graphene_type._meta.enum.__members__['en'].value == 'English'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_should_scalar_list_convert_list():
 | 
			
		||||
    assert_column_conversion(ScalarListType(), graphene.List)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_should_manytomany_convert_connectionorlist():
 | 
			
		||||
    registry = Registry()
 | 
			
		||||
    dynamic_field = convert_sqlalchemy_relationship(Reporter.pets.property, registry)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user