import { GraphQLScalarType } from "graphql" ; import { ArgsType , Field } from 'type-graphql' ; export const JosnScalar = new GraphQLScalarType ( { name : "JSON" , description : "验证 JSON 类型" , parseValue ( value ) { checkIsObject ( value ) ; return value ; } , serialize ( value ) { return value ; } , } ) ; @ ArgsType ( ) export class DefaultQuery { @ Field ( ( ) => JosnScalar , { nullable : true } ) filter : any ; @ Field ( ( ) => JosnScalar , { nullable : true } ) order : - 1 ; @ Field ( ( ) => JosnScalar , { nullable : true } ) page : any ; } /**
  * 验证
*/ function checkIsObject ( value ) { if ( Object . prototype . toString . call ( value ) !== '[object Object]' ) { throw new Error ( '亲，参数不是一个对象呢！' ) ; } }