import { Scalar, CustomScalar } from "@nestjs/graphql"; import { Kind, ValueNode } from "graphql"; import { fromCursor, toCursor } from "../utils"; @Scalar("Cursor") export class CursorScalar implements CustomScalar { description = "Cursor scalar type"; parseValue(value: string): string | null { return fromCursor(value); } serialize(value: string): string | null { if (value) { return toCursor({ value }); } else { return null; } } //@ts-ignore parseLiteral(ast: ValueNode): string | null { if (ast.kind === Kind.STRING) { return fromCursor(ast.value); } return null; } }