About writing output of an Enum in Graphene

0

I am working with graphene and graphene-django and I have a problem with a field, that the values of choices are a number. When making a query, the result is "A_1" and it should be 1 (integer). For example:

class Foo(models.Model):
   score = models.Integer(choices=((1, 1), (2, 2), (3, 3), (4, 4), (5, 5)))

And making this query:

query {
    foo {
       score
    }
}

gives me this result:

{
  "data": {
    "foo": {
      "source": "A_1"
    }
  }
}

I have been researching and graphene-django creates a Enum with choices and there is a function that validates the name of the choices item.

def convert_choice_name(name):
    name = to_const(force_text(name))
    try:
        assert_valid_name(name)
    except AssertionError:
        name = "A_%s" % name
    return name

the function assert_valida_name has a regular expression that validates that it starts with a letter or a '_'

r'^[_a-zA-Z][_a-zA-Z0-9]*$'

So, the question is: how can I overwrite the output that graphene gives me?

Thank you.

    
asked by Julián Cortés 26.01.2017 в 20:57
source

0 answers