import { GraphQLScalarType , Kind } from "graphql" ; import { ObjectId } from "mongodb" ; export const ObjectIdScalar = new GraphQLScalarType ( { name : "ObjectId" , description : "Mongo object id scalar type" , parseValue ( value ) { return new ObjectId ( value ) ; } , serialize ( value ) { return value . toHexString ( ) ; } , parseLiteral ( ast ) { if ( ast . kind === Kind . STRING ) { return new ObjectId ( ast . value ) ; } return null ; } , } ) ;