File tree Expand file tree Collapse file tree 3 files changed +15
-10
lines changed Expand file tree Collapse file tree 3 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,11 @@ def description(self):
70
70
71
71
72
72
def generate_enum_name (django_model_meta , field ):
73
- if graphene_settings .DJANGO_CHOICE_FIELD_ENUM_V3_NAMING is True :
73
+ if graphene_settings .DJANGO_CHOICE_FIELD_ENUM_CUSTOM_NAME and callable (
74
+ graphene_settings .DJANGO_CHOICE_FIELD_ENUM_CUSTOM_NAME
75
+ ):
76
+ name = graphene_settings .DJANGO_CHOICE_FIELD_ENUM_CUSTOM_NAME (field )
77
+ elif graphene_settings .DJANGO_CHOICE_FIELD_ENUM_V3_NAMING is True :
74
78
name = "DjangoModel{app_label}{object_name}{field_name}Choices" .format (
75
79
app_label = to_camel_case (django_model_meta .app_label .title ()),
76
80
object_name = django_model_meta .object_name ,
Original file line number Diff line number Diff line change 38
38
"CAMELCASE_ERRORS" : False ,
39
39
# Set to True to enable v3 naming convention for choice field Enum's
40
40
"DJANGO_CHOICE_FIELD_ENUM_V3_NAMING" : False ,
41
+ "DJANGO_CHOICE_FIELD_ENUM_CUSTOM_NAME" : None ,
41
42
}
42
43
43
44
if settings .DEBUG :
Original file line number Diff line number Diff line change @@ -514,14 +514,14 @@ class Query(ObjectType):
514
514
query: Query
515
515
}
516
516
517
- enum DjangoModelTestsPetModelKindChoices {
517
+ enum CustomEnumKind {
518
518
CAT
519
519
DOG
520
520
}
521
521
522
522
type PetModelKind {
523
523
id: ID!
524
- kind: DjangoModelTestsPetModelKindChoices !
524
+ kind: CustomEnumKind !
525
525
}
526
526
527
527
type Query {
@@ -531,15 +531,13 @@ class Query(ObjectType):
531
531
)
532
532
graphene_settings .DJANGO_CHOICE_FIELD_ENUM_V3_NAMING = False
533
533
534
- def test_django_objecttype_choices_override_enum (self , PetModel ):
535
- def convert_choice (model , field_name , ** kwargs ):
536
- return convert_choice_field_to_enum (
537
- model ._meta .get_field (field_name ), ** kwargs
538
- )
534
+ def test_django_objecttype_choices_custom_enum_name (self , PetModel ):
535
+ def custom_name (field ):
536
+ return f"CustomEnum{ field .name .title ()} "
539
537
540
- class PetModelKind (DjangoObjectType ):
541
- kind = Field (convert_choice (PetModel , "kind" , name = "CustomEnumName" ))
538
+ graphene_settings .DJANGO_CHOICE_FIELD_ENUM_CUSTOM_NAME = custom_name
542
539
540
+ class PetModelKind (DjangoObjectType ):
543
541
class Meta :
544
542
model = PetModel
545
543
fields = ["id" , "kind" ]
@@ -570,3 +568,5 @@ class Query(ObjectType):
570
568
}
571
569
"""
572
570
)
571
+
572
+ graphene_settings .DJANGO_CHOICE_FIELD_ENUM_CUSTOM_NAME = None
You can’t perform that action at this time.
0 commit comments