How to use 'Decimal' as a field type in GraphQL schema? How to use 'Decimal' as a field type in GraphQL schema? express express

How to use 'Decimal' as a field type in GraphQL schema?


I looked at the source code for this module can came up with this:

///  I M P O R Timport Big from "big.js";import { GraphQLScalarType, Kind } from "graphql";///  E X P O R Texport default new GraphQLScalarType({  name: "Decimal",  description: "The `Decimal` scalar type to represent currency values",  serialize(value) {    return new Big(value);  },  parseLiteral(ast) {    if (ast.kind !== Kind.STRING) {      // @ts-ignore | TS2339      throw new TypeError(`${String(ast.value)} is not a valid decimal value.`);    }    return Big(ast.value);  },  parseValue(value) {    return Big(value);  }});

Then, I add the reference to my resolver so I can just add Decimal to my SDL code.