11from textwrap import dedent
2- from graphql import OperationType
32
4- from graphene .utils . str_converters import to_snake_case
3+ from graphene .compat . middleware import enum_value_convertor_middleware
54from ..argument import Argument
6- from ..definitions import GrapheneEnumType
75from ..enum import Enum , PyEnum
86from ..field import Field
97from ..inputfield import InputField
@@ -398,12 +396,6 @@ class MyMutations(ObjectType):
398396 assert results .data ["setFavColor" ]["favColor" ] == Color .RED .name
399397
400398
401- def get_underlying_type (_type ):
402- while hasattr (_type , "of_type" ):
403- _type = _type .of_type
404- return _type
405-
406-
407399def test_enum_mutation_compat ():
408400 from enum import Enum as PyEnum
409401
@@ -436,23 +428,6 @@ def mutate(self, info, fav_color):
436428 class MyMutations (ObjectType ):
437429 set_fav_color = SetFavColor .Field ()
438430
439- def enum_compat_middleware (next , root , info , ** args ):
440- operation = info .operation .operation
441- if operation == OperationType .MUTATION :
442- input_arguments = info .parent_type .fields [info .field_name ].args
443- for arg_name , arg in input_arguments .items ():
444- _type = get_underlying_type (arg .type )
445- if isinstance (_type , GrapheneEnumType ):
446- # Convert inputs to value
447- arg_name = to_snake_case (arg_name )
448- input_value = args .get (arg_name , None )
449- if input_value and isinstance (
450- input_value , _type .graphene_type ._meta .enum
451- ):
452- args [arg_name ] = args [arg_name ].value
453-
454- return next (root , info , ** args )
455-
456431 schema = Schema (query = Query , mutation = MyMutations )
457432
458433 results = schema .execute (
@@ -461,7 +436,7 @@ def enum_compat_middleware(next, root, info, **args):
461436 favColor
462437 }
463438 }""" ,
464- middleware = [enum_compat_middleware ],
439+ middleware = [enum_value_convertor_middleware ],
465440 )
466441 assert not results .errors
467442
0 commit comments