我结束了使用自定义标量。如果这会自动转换为石墨烯-django中更好的标量,那会更好,但这是我如何解决这个问题。我写了一个converter.py文件与自定义BigInt有标,它采用了浮动,而不是一个int,如果我们有比MAX_INT
# converter.py
from graphene.types import Scalar
from graphql.language import ast
from graphene.types.scalars import MIN_INT, MAX_INT
class BigInt(Scalar):
"""
BigInt is an extension of the regular Int field
that supports Integers bigger than a signed
32-bit integer.
"""
@staticmethod
def big_to_float(value):
num = int(value)
if num > MAX_INT or num < MIN_INT:
return float(int(num))
return num
serialize = big_to_float
parse_value = big_to_float
@staticmethod
def parse_literal(node):
if isinstance(node, ast.IntValue):
num = int(node.value)
if num > MAX_INT or num < MIN_INT:
return float(int(num))
return num
然后
# schema.py
from .converter import BigInt
class MatchType(DjangoObjectType):
game_id = graphene.Field(BigInt)
class Meta:
model = Match
interfaces = (graphene.Node,)
filter_fields = {}
大的数