import { ClassType } from "type-graphql"; import { ObjectType, GraphQLISODateTime, Field, ID as GraphqlID } from "@nestjs/graphql"; import { Filterable } from "../helpers"; import { CursorScalar } from "../scalars"; import { Type } from "class-transformer"; import { ConnectionOptions } from "../helpers"; export class ID extends String {} @ObjectType({ isAbstract: true }) export abstract class Node { @Filterable() @Field(() => GraphqlID) id!: ID; @Filterable() @Type(() => Date) @Field(() => GraphQLISODateTime) createdAt!: Date; @Filterable() @Type(() => Date) @Field(() => GraphQLISODateTime) updatedAt!: Date; } @ObjectType() class PageInfo { @Field(() => CursorScalar, { nullable: true }) startCursor?: string; @Field({ nullable: true }) hasNextPage!: boolean; @Field({ nullable: true }) hasPreviousPage!: boolean; @Field(() => CursorScalar, { nullable: true }) endCursor?: string; } export function ExtendConnectionType( TItemClass: ClassType, { relationship }: ConnectionOptions | undefined = { relationship: "" } ): any { @ObjectType(`${TItemClass.name}${relationship}Edge`) class EdgeTypeClass { @Field(() => TItemClass) node!: TItem; @Field(() => CursorScalar) cursor!: string; } @ObjectType(`${TItemClass.name}${relationship}Connection`, { isAbstract: true, }) abstract class ConnectionTypeClass { @Field(() => [EdgeTypeClass], { nullable: true }) edges?: [EdgeTypeClass]; @Field(() => PageInfo) pageInfo!: PageInfo; } return ConnectionTypeClass; } @ObjectType() export class GeoLocation { @Field() longitude?: string; @Field() latitude?: string; }