'how I can add a custom scalar with different formats in type-graphql to generate GraphQL schema

I tried to generate a GraphQl schema using type-graphql lib I want the field value to accept any data type but it only takes a string. I have created a custom scalar with the name SettingValueScalar but it's not working as well

import { ObjectID } from 'mongodb'
import 'reflect-metadata'
import { Field, InputType, Int, ObjectType } from 'type-graphql'
import { DateScalar } from '../scalars/date.scalar'
import { SettingValueScalar } from '../scalars/setting-value.scalar'

@ObjectType()
@InputType('SettingInput')

export class Setting implements MSetting {
readonly _id!: ObjectID

@Field(() => Int)
 id!: number

 @Field({ nullable: true })
  slug?: string

 @Field({ nullable: true })
 domain?: string

 @Field(()=>SettingValueScalar,{ nullable: true })
 value?: string| number | string[] | number[]

 @Field(() => DateScalar, { nullable: true })
 createdAt?: Date

 @Field(() => DateScalar, { nullable: true })
 updatedAt?: Date

 }

SettingValueScalar

 import { GraphQLScalarType, Kind } from 'graphql'

 export const SettingValueScalar = new GraphQLScalarType({
 name: 'SettingValue',
 description: 'Setting value scalar type',

 serialize(value: any): any {
  return value
 },
 parseValue(value: any): any {
  return value
 },
 parseLiteral(ast) {
  return last
 },
 })


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source