feat: add findAll and findUnique resolver for universal objects (#1576)

* wip: refacto and start creating custom resolver

* feat: findMany & findUnique of a custom entity

* feat: wip pagination

* feat: initial metadata migration

* feat: universal findAll with pagination

* fix: clean small stuff in pagination

* fix: test

* fix: miss file

* feat: rename custom into universal

* feat: create metadata schema in default database

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Jérémy M
2023-09-21 02:24:13 +02:00
committed by GitHub
parent dafe08ef78
commit b1171e22a3
41 changed files with 1043 additions and 29 deletions
@@ -0,0 +1,11 @@
import { ArgsType, Field } from '@nestjs/graphql';
import { IsNotEmpty, IsString } from 'class-validator';
@ArgsType()
export class BaseUniversalArgs {
@Field(() => String)
@IsNotEmpty()
@IsString()
entity: string;
}
@@ -0,0 +1,10 @@
import { ArgsType, Field } from '@nestjs/graphql';
import { BaseUniversalArgs } from './base-universal.args';
import { UniversalEntityInput } from './universal-entity.input';
@ArgsType()
export class DeleteOneUniversalArgs extends BaseUniversalArgs {
@Field(() => UniversalEntityInput, { nullable: true })
where?: UniversalEntityInput;
}
@@ -0,0 +1,35 @@
import { ArgsType, Field, Int } from '@nestjs/graphql';
import GraphQLJSON from 'graphql-type-json';
import { IsNotEmpty, IsString } from 'class-validator';
import { ConnectionArgs } from 'src/utils/pagination';
import { UniversalEntityInput } from './universal-entity.input';
import { UniversalEntityOrderByRelationInput } from './universal-entity-order-by-relation.input';
@ArgsType()
export class FindManyUniversalArgs extends ConnectionArgs {
@Field(() => String)
@IsNotEmpty()
@IsString()
entity: string;
@Field(() => UniversalEntityInput, { nullable: true })
where?: UniversalEntityInput;
@Field(() => UniversalEntityOrderByRelationInput, { nullable: true })
orderBy?: UniversalEntityOrderByRelationInput;
@Field(() => GraphQLJSON, { nullable: true })
cursor?: UniversalEntityInput;
@Field(() => Int, { nullable: true })
take?: number;
@Field(() => Int, { nullable: true })
skip?: number;
@Field(() => [String], { nullable: true })
distinct?: Array<string>;
}
@@ -0,0 +1,10 @@
import { ArgsType, Field } from '@nestjs/graphql';
import { BaseUniversalArgs } from './base-universal.args';
import { UniversalEntityInput } from './universal-entity.input';
@ArgsType()
export class FindUniqueUniversalArgs extends BaseUniversalArgs {
@Field(() => UniversalEntityInput, { nullable: true })
where?: UniversalEntityInput;
}
@@ -0,0 +1,29 @@
import { Field, InputType } from '@nestjs/graphql';
import { registerEnumType } from '@nestjs/graphql';
import GraphQLJSON from 'graphql-type-json';
export enum TypeORMSortOrder {
ASC = 'ASC',
DESC = 'DESC',
}
registerEnumType(TypeORMSortOrder, {
name: 'TypeORMSortOrder',
description: undefined,
});
@InputType()
export class UniversalEntityOrderByRelationInput {
@Field(() => TypeORMSortOrder, { nullable: true })
id?: keyof typeof TypeORMSortOrder;
@Field(() => GraphQLJSON, { nullable: true })
data?: Record<string, keyof typeof TypeORMSortOrder>;
@Field(() => TypeORMSortOrder, { nullable: true })
createdAt?: keyof typeof TypeORMSortOrder;
@Field(() => TypeORMSortOrder, { nullable: true })
updatedAt?: keyof typeof TypeORMSortOrder;
}
@@ -0,0 +1,18 @@
import { Field, ID, InputType } from '@nestjs/graphql';
import GraphQLJSON from 'graphql-type-json';
@InputType()
export class UniversalEntityInput {
@Field(() => ID, { nullable: true })
id?: string;
@Field(() => GraphQLJSON, { nullable: true })
data?: Record<string, unknown>;
@Field(() => Date, { nullable: true })
createdAt?: Date;
@Field(() => Date, { nullable: true })
updatedAt?: Date;
}
@@ -0,0 +1,13 @@
import { ArgsType, Field } from '@nestjs/graphql';
import { BaseUniversalArgs } from './base-universal.args';
import { UniversalEntityInput } from './universal-entity.input';
@ArgsType()
export class UpdateOneCustomArgs extends BaseUniversalArgs {
@Field(() => UniversalEntityInput, { nullable: false })
data!: UniversalEntityInput;
@Field(() => UniversalEntityInput, { nullable: true })
where?: UniversalEntityInput;
}