question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lowercased choices getting uppercased in Graphene response

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

11reactions
Hisparcommented, Oct 23, 2018

Adding the field as a String, seems to be enough to solve the problem.

class MyObject(DjangoObjectType):
   type = graphene.String()
3reactions
jordanmkonczcommented, Mar 7, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found