Lowercased choices getting uppercased in Graphene response
See original GitHub issueI’ve the following model:
class TripSuggestedGadget(models.Model):
trip = models.ForeignKey(
Trip,
related_name='suggested_gadgets'
)
type = models.CharField(
max_length=50,
choices=SUGGESTED_GADGET_TYPES
)
description = models.TextField()
Here are the choices referred above:
SUGGESTED_GADGET_TYPES = (
('camera', u'Cámara'),
('flash', u'Flash'),
('tripod', u'Trípode'),
('umbrella', u'Sombrilla'),
)
In the graph response here’s what I’m getting:
...
"edges": [
{
"node": {
"id": "VHJpcFN1Z2dlc3RlZEdhZGdldE5vZGU6MQ==",
"type": "CAMERA",
"description": "Cámara de formato medio",
"__typename": "TripSuggestedGadgetNode"
},
"__typename": "TripSuggestedGadgetNodeEdge"
},
{
"node": {
"id": "VHJpcFN1Z2dlc3RlZEdhZGdldE5vZGU6Mg==",
"type": "FLASH",
"description": "Flash",
"__typename": "TripSuggestedGadgetNode"
},
"__typename": "TripSuggestedGadgetNodeEdge"
},
{
"node": {
"id": "VHJpcFN1Z2dlc3RlZEdhZGdldE5vZGU6Mw==",
"type": "TRIPOD",
"description": "Trípode liviano para poderlo llevar",
"__typename": "TripSuggestedGadgetNode"
},
"__typename": "TripSuggestedGadgetNodeEdge"
}
]
...
As you may notice my choices are lowercased, but response uppercased.
I’ve seen @BrianChapman comment in #67 regarding the same problem, but preferred to open this new one because #67 is not directly related.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Overwrite django choices output in graphene - Stack Overflow
I found a function that convert the choices values. def convert_choice_name(name): name = to_const(force_text(name)) try: assert_valid_name(name) ...
Read more >FastAPI Microservice Patterns: GraphQL API | by Florian Kromer
With Django, I've used GraphQL with a schema-first approach using Ariadne as well as with a code-first approach using Graphene and a bunch...
Read more >Hardware questions & answers for quizzes and worksheets - Quizizz
answer choices. GPy. FLAPS (Floating-Point Applications Per Second) ... It must be a mixture of both uppercase and lowercase letters.
Read more >Interfacial characterization of functionalized graphene-epoxy ...
Abstract. The interface of graphene/epoxy was studied using molecular dynamics simulations by calculating the work of separation and traction-separation ...
Read more >The Big Reveal: What's Behind Nutrition Labels?
Let's start with calories. Actually, the word “Calorie” (uppercase C) is what chemists call a “kilocalorie,” or 1,000 calories (lowercase c). To distinguish ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Adding the field as a String, seems to be enough to solve the problem.
Just ran into this issue too and was very confused that Graphene was forcing all my enum string values to uppercase. Given that Django itself treats enum strings used as
choices
as being case-sensitive, and doesn’t force them to be uppercase, I think it’s important that Graphene doesn’t try to force them to be uppercase.If GraphQL recommends string constants be uppercase, perhaps it’s worth mentioning this as a suggestion in the Graphene docs somewhere, but I think the choice needs to be left to the developer.
In the meantime, @Hispar’s fix of marking the field as being a
String()
is working for me.