How can I handle Big Int with GraphQL?

287 Views Asked by At

I've an Django Model field with BigInt type, How can i map this in graphql schema, is there anything available like BigInt like Int type in Graphql?

I'm using graphene library FYI

My Schema:

type MyModelObject {
  complaintId: BigInt
  createdBy: User!
  complaintNumber: String!
}

I got below warning/error in IDE

The field type 'BigInt' is not present when resolving type 'MyModelObject'
1

There are 1 best solutions below

0
ThisaruG On

There is no built-in support for this, AFAIK. But the GraphQL custom scalars are designed for this kind of requirement. You can use Graphene Custom scalars to define a new scalar type for BigInt.

from graphene.types import Scalar
from graphql.language import ast

class BigInt(Scalar):
    '''BigInt Scalar Description'''

    @staticmethod
    def serialize(bigInt):
        # Can serialize this by converting it to a string.
        return str(bigInt)

    @staticmethod
    def parse_literal(node, _variables=None):
        # Parse literal

    @staticmethod
    def parse_value(value):
        # Parse the value

Check the Graphene documentation for more information.