mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-10-31 16:07:36 +03:00 
			
		
		
		
	Add support for dict field
This commit is contained in:
		
							parent
							
								
									f747102e35
								
							
						
					
					
						commit
						68f6281ec8
					
				|  | @ -4,6 +4,7 @@ from rest_framework import serializers | ||||||
| import graphene | import graphene | ||||||
| 
 | 
 | ||||||
| from ..utils import import_single_dispatch | from ..utils import import_single_dispatch | ||||||
|  | from .types import DictType | ||||||
| 
 | 
 | ||||||
| singledispatch = import_single_dispatch() | singledispatch = import_single_dispatch() | ||||||
| 
 | 
 | ||||||
|  | @ -80,3 +81,8 @@ def convert_serializer_field_to_list(field, is_input=True): | ||||||
|     child_type = get_graphene_type_from_serializer_field(field.child) |     child_type = get_graphene_type_from_serializer_field(field.child) | ||||||
| 
 | 
 | ||||||
|     return (graphene.List, child_type) |     return (graphene.List, child_type) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @get_graphene_type_from_serializer_field.register(serializers.DictField) | ||||||
|  | def convert_serializer_field_to_dict(field): | ||||||
|  |     return DictType | ||||||
|  |  | ||||||
|  | @ -5,6 +5,7 @@ from py.test import raises | ||||||
| import graphene | import graphene | ||||||
| 
 | 
 | ||||||
| from ..serializer_converter import convert_serializer_field | from ..serializer_converter import convert_serializer_field | ||||||
|  | from ..types import DictType | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _get_type(rest_framework_field, **kwargs): | def _get_type(rest_framework_field, **kwargs): | ||||||
|  | @ -115,3 +116,7 @@ def test_should_list_convert_to_list(): | ||||||
|     field_b = assert_conversion(StringListField, graphene.List) |     field_b = assert_conversion(StringListField, graphene.List) | ||||||
| 
 | 
 | ||||||
|     assert field_b.of_type == graphene.String |     assert field_b.of_type == graphene.String | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def test_should_dict_convert_dict(): | ||||||
|  |     assert_conversion(serializers.DictField, DictType) | ||||||
|  |  | ||||||
|  | @ -1,6 +1,12 @@ | ||||||
| import graphene | import graphene | ||||||
|  | from graphene.types.unmountedtype import UnmountedType | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ErrorType(graphene.ObjectType): | class ErrorType(graphene.ObjectType): | ||||||
|     field = graphene.String() |     field = graphene.String() | ||||||
|     messages = graphene.List(graphene.String) |     messages = graphene.List(graphene.String) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class DictType(UnmountedType): | ||||||
|  |     key = graphene.String() | ||||||
|  |     value = graphene.String() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user