我正在與graphene
和graphene-django
一起工作,我有一個IntegerField
有問題的選項。 graphene
創建Enum
,如果值爲1,則輸出爲「A_1」;如果值爲2等等,則爲「A_2」。例如:覆蓋石墨烯中的django選項輸出
# model
class Foo(models.Model):
score = models.IntegerField(choices=((1, 1), (2, 2), (3, 3), (4, 4), (5, 5)))
# query
query {
foo {
score
}
}
# response
{
"data": {
"foo": {
"source": "A_1"
}
}
}
我找到了一個函數來轉換選項值。
def convert_choice_name(name):
name = to_const(force_text(name))
try:
assert_valid_name(name)
except AssertionError:
name = "A_%s" % name
return name
而且assert_valid_name
有這樣的正則表達式:
r'^[_a-zA-Z][_a-zA-Z0-9]*$'
因此,無論用數字開頭,將其轉換爲 「A _...」。
我如何覆蓋這個輸出?