Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Scalar } from '@nestjs/graphql';
import { Kind, ASTNode } from 'graphql';
import { Types } from 'mongoose';
@Scalar('ObjectId')
export class ObjectIdScalar {
description = 'MongoDB ObjectId scalar type, sent as 24 byte Hex String';
parseValue(value: string) {
return new Types.ObjectId(value); // value from the client
}
serialize(value: Types.ObjectId) {
return value.toHexString(); // value sent to the client
}
parseLiteral(ast: ASTNode) {
if (ast.kind === Kind.STRING) {
return new Types.ObjectId(ast.value); // ast value is always in string format
}
return null;
import { CustomScalar, Scalar } from '@nestjs/graphql';
import { Kind } from 'graphql';
@Scalar('Date', type => Date)
export class DateScalar implements CustomScalar {
description: string = 'Date custom scalar type';
parseValue(value: number): Date {
return new Date(value); // value from the client
}
serialize(value: Date): number {
return value.getTime(); // value sent to the client
}
parseLiteral(ast: any): Date {
if (ast.kind === Kind.INT) {
return new Date(ast.value);
}
return null;
import { CustomScalar, Scalar } from '@nestjs/graphql';
import { Kind } from 'graphql';
@Scalar('Date', type => Date)
export class DateScalar implements CustomScalar {
description = 'Date custom scalar type';
parseValue(value: number): Date {
return new Date(value); // value from the client
}
serialize(value: Date): number {
return value.getTime(); // value sent to the client
}
parseLiteral(ast: any): Date {
if (ast.kind === Kind.INT) {
return new Date(ast.value);
}
return null;
import { CustomScalar, Scalar } from '@nestjs/graphql';
import { Kind } from 'graphql';
@Scalar('Date')
export class DateScalar implements CustomScalar {
description = 'Date custom scalar type';
parseValue(value: number): Date {
return new Date(value); // value from the client
}
serialize(value: Date): number {
return value.getTime(); // value sent to the client
}
parseLiteral(ast: any): Date {
if (ast.kind === Kind.INT) {
return new Date(ast.value);
}
return null;
import { Scalar } from '@nestjs/graphql';
import { Kind } from 'graphql';
@Scalar('DateTime')
export class DateTimeScaler {
description = 'DateTime custom scalar type';
parseValue(value) {
return new Date(value); // value from the client
}
serialize(value) {
return value.getTime(); // value sent to the client
}
parseLiteral(ast) {
if (ast.kind === Kind.INT) {
return parseInt(ast.value, 10); // ast value is always in string format
}
return null;
import { CustomScalar, Scalar } from '@nestjs/graphql';
import { Kind } from 'graphql';
@Scalar('Date', type => Date)
export class DateScalar implements CustomScalar {
description = 'Date custom scalar type';
parseValue(value: string): Date {
return new Date(value); // value from the client
}
serialize(value: Date): string {
return new Date(value).toISOString(); // value sent to the client
}
parseLiteral(ast: any): Date {
if (ast.kind === Kind.INT) {
return new Date(ast.value);
}
return null;
import {Scalar} from '@nestjs/graphql';
import {Kind} from 'graphql';
import {DateTime} from 'luxon';
@Scalar('Date')
export class DateScalar {
description = 'Date custom scalar type';
parseValue(value) {
return new Date(value); // value from the client
}
serialize(value: Date|DateTime) {
if (value instanceof DateTime) {
return value.toJSON();
}
return value.toISOString(); // value sent to the client
}
parseLiteral(ast) {
if (ast.kind === Kind.STRING) {
import { CustomScalar, Scalar } from '@nestjs/graphql'
import { Kind } from 'graphql'
@Scalar('Date', type => Date)
export class DateScalar implements CustomScalar {
description = 'Date custom scalar type'
parseValue(value: number): Date {
return new Date(value) // value from the client
}
serialize(value: Date): number {
return value.getTime() // value sent to the client
}
parseLiteral(ast: any): Date {
if (ast.kind === Kind.INT) {
return new Date(ast.value)
}
return null
import { CustomScalar, Scalar } from '@nestjs/graphql';
import { Kind } from 'graphql';
@Scalar('Date')
export class DateScalar implements CustomScalar {
description = 'Date custom scalar type';
parseValue(value: number): Date {
return new Date(value); // value from the client
}
serialize(value: Date): number {
return value.getTime(); // value sent to the client
}
parseLiteral(ast: any): Date {
if (ast.kind === Kind.INT) {
return new Date(ast.value);
}
return null;
import { CustomScalar, Scalar } from '@nestjs/graphql';
import { Kind } from 'graphql';
@Scalar('Date', type => Date)
export class DateScalar implements CustomScalar {
description: string = 'Date custom scalar type';
parseValue(value: number): Date {
return new Date(value); // value from the client
}
serialize(value: Date): number {
return value.getTime(); // value sent to the client
}
parseLiteral(ast: any): Date {
if (ast.kind === Kind.INT) {
return new Date(ast.value);
}
return null;