How to use the @nestjs/graphql.Scalar function in @nestjs/graphql

To help you get started, we’ve selected a few @nestjs/graphql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EricKit / nest-user-auth / src / scalars / object-id.scalar.ts View on Github external
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;
github magishift / magishift.core / packages / crud.1 / src / scalars / date.scalar.ts View on Github external
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;
github nestjs / nest / sample / 23-type-graphql / src / common / scalars / date.scalar.ts View on Github external
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;
github vip-git / react-ssr-advanced-seed / src / server / app / scalars / data.scalar.ts View on Github external
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;
github awesome-graphql-space / lina / src / server / commons / scalers / date-time-scaler.ts View on Github external
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;
github fivethree-team / nestjs-prisma-starter / src / common / scalars / date.scalar.ts View on Github external
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;
github neoteric-eu / nestjs-auth / src / app / message / date.scalar.ts View on Github external
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) {
github chnirt / nestjs-graphql-best-practice / src / config / graphql / scalars / date.scalar.ts View on Github external
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
github nestjs / nest / sample / 12-graphql-apollo / src / common / scalars / date.scalar.ts View on Github external
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;
github magishift / magishift.core / src / crud / scalars / date.scalar.ts View on Github external
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;