Skip to content

API Generator: Improve performance by not formatting generated files with ESLint anymore #3789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/wise-candles-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/api-generator": patch
---

Improve Performance: Don't format generated files with eslint anymore

When scaffolding run eslint as first step.
2 changes: 1 addition & 1 deletion demo/api/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import eslintConfigNestJs from "@comet/eslint-config/nestjs.js";
/** @type {import('eslint')} */
const config = [
{
ignores: ["src/db/migrations/**", "dist/**", "src/**/*.generated.ts"],
ignores: ["src/db/migrations/**", "dist/**", "src/**/*.generated.ts", "src/**/generated/**"],
},
...eslintConfigNestJs,
];
Expand Down
4 changes: 1 addition & 3 deletions demo/api/src/footer/generated/dto/footer.input.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// This file has been generated by comet api-generator.
// You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment.
import { BlockInputInterface, isBlockInputInterface, RootBlockInputScalar } from "@comet/cms-api";
import { Field, InputType } from "@nestjs/graphql";
import { Transform } from "class-transformer";
import { IsNotEmpty, ValidateNested } from "class-validator";

import { BlockInputInterface, RootBlockInputScalar, isBlockInputInterface } from "@comet/cms-api";
import { FooterContentBlock } from "../../blocks/footer-content.block";

@InputType()
export class FooterInput {
@IsNotEmpty()
Expand Down
31 changes: 11 additions & 20 deletions demo/api/src/footer/generated/footer.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,45 @@
// This file has been generated by comet api-generator.
// You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment.
import { RequiredPermission } from "@comet/cms-api";
import { EntityManager } from "@mikro-orm/postgresql";
import { Args, Mutation, Query, Resolver } from "@nestjs/graphql";

import { FooterScope } from "../dto/footer-scope";
import { RequiredPermission } from "@comet/cms-api";
import { Footer } from "../entities/footer.entity";
import { FooterInput } from "./dto/footer.input";
import { FooterScope } from "../dto/footer-scope";
import { FootersService } from "./footers.service";

import { FooterInput } from "./dto/footer.input";
@Resolver(() => Footer)
@RequiredPermission(["pageTree"])
export class FooterResolver {
constructor(
private readonly entityManager: EntityManager,
private readonly footersService: FootersService,
) {}

constructor(private readonly entityManager: EntityManager, private readonly footersService: FootersService) { }
@Query(() => Footer, { nullable: true })
async footer(@Args("scope", { type: () => FooterScope }) scope: FooterScope): Promise<Footer | null> {
async footer(
@Args("scope", { type: () => FooterScope })
scope: FooterScope): Promise<Footer | null> {
const footers = await this.entityManager.find(Footer, { scope });
if (footers.length > 1) {
throw new Error("There must be only one footer");
}

return footers.length > 0 ? footers[0] : null;
}

@Mutation(() => Footer)
async saveFooter(
@Args("scope", { type: () => FooterScope }) scope: FooterScope,
@Args("input", { type: () => FooterInput }) input: FooterInput,
): Promise<Footer> {
@Args("scope", { type: () => FooterScope })
scope: FooterScope,
@Args("input", { type: () => FooterInput })
input: FooterInput): Promise<Footer> {
let footer = await this.entityManager.findOne(Footer, { scope });

if (!footer) {
footer = this.entityManager.create(Footer, {
...input,
content: input.content.transformToBlockData(),
scope,
});
}

footer.assign({
...input,
content: input.content.transformToBlockData(),
});

await this.entityManager.flush();

return footer;
}
}
6 changes: 2 additions & 4 deletions demo/api/src/footer/generated/footers.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// This file has been generated by comet api-generator.
// You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment.
import { Injectable } from "@nestjs/common";

@Injectable()
export class FootersService {}
export class FootersService {
}
9 changes: 2 additions & 7 deletions demo/api/src/news/generated/dto/news-list.args.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
// This file has been generated by comet api-generator.
// You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment.
import { OffsetBasedPaginationArgs } from "@comet/cms-api";
import { ArgsType, Field } from "@nestjs/graphql";
import { Type } from "class-transformer";
import { IsOptional, IsString, ValidateNested } from "class-validator";

import { NewsContentScope } from "../../entities/news.entity";
import { OffsetBasedPaginationArgs } from "@comet/cms-api";
import { NewsFilter } from "./news.filter";
import { NewsSort } from "./news.sort";

import { NewsContentScope } from "../../entities/news.entity";
@ArgsType()
export class NewsListArgs extends OffsetBasedPaginationArgs {
@Field(() => NewsContentScope)
@ValidateNested()
@Type(() => NewsContentScope)
scope: NewsContentScope;

@Field({ nullable: true })
@IsOptional()
@IsString()
search?: string;

@Field(() => NewsFilter, { nullable: true })
@ValidateNested()
@Type(() => NewsFilter)
@IsOptional()
filter?: NewsFilter;

@Field(() => [NewsSort], { nullable: true })
@ValidateNested({ each: true })
@Type(() => NewsSort)
Expand Down
21 changes: 5 additions & 16 deletions demo/api/src/news/generated/dto/news.filter.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,68 @@
// This file has been generated by comet api-generator.
// You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment.
import { createEnumFilter, DateTimeFilter, IdFilter, OneToManyFilter, StringFilter } from "@comet/cms-api";
import { StringFilter, DateTimeFilter, OneToManyFilter, IdFilter, createEnumFilter } from "@comet/cms-api";
import { Field, InputType } from "@nestjs/graphql";
import { Type } from "class-transformer";
import { IsOptional, ValidateNested } from "class-validator";

import { NewsCategory, NewsStatus } from "../../entities/news.entity";

@InputType()
class NewsStatusEnumFilter extends createEnumFilter(NewsStatus) {}
class NewsStatusEnumFilter extends createEnumFilter(NewsStatus) {
}
@InputType()
class NewsCategoryEnumFilter extends createEnumFilter(NewsCategory) {}

class NewsCategoryEnumFilter extends createEnumFilter(NewsCategory) {
}
@InputType()
export class NewsFilter {
@Field(() => IdFilter, { nullable: true })
@ValidateNested()
@IsOptional()
@Type(() => IdFilter)
id?: IdFilter;

@Field(() => StringFilter, { nullable: true })
@ValidateNested()
@IsOptional()
@Type(() => StringFilter)
slug?: StringFilter;

@Field(() => StringFilter, { nullable: true })
@ValidateNested()
@IsOptional()
@Type(() => StringFilter)
title?: StringFilter;

@Field(() => NewsStatusEnumFilter, { nullable: true })
@ValidateNested()
@IsOptional()
@Type(() => NewsStatusEnumFilter)
status?: NewsStatusEnumFilter;

@Field(() => DateTimeFilter, { nullable: true })
@ValidateNested()
@IsOptional()
@Type(() => DateTimeFilter)
date?: DateTimeFilter;

@Field(() => NewsCategoryEnumFilter, { nullable: true })
@ValidateNested()
@IsOptional()
@Type(() => NewsCategoryEnumFilter)
category?: NewsCategoryEnumFilter;

@Field(() => OneToManyFilter, { nullable: true })
@ValidateNested()
@IsOptional()
@Type(() => OneToManyFilter)
comments?: OneToManyFilter;

@Field(() => DateTimeFilter, { nullable: true })
@ValidateNested()
@IsOptional()
@Type(() => DateTimeFilter)
createdAt?: DateTimeFilter;

@Field(() => DateTimeFilter, { nullable: true })
@ValidateNested()
@IsOptional()
@Type(() => DateTimeFilter)
updatedAt?: DateTimeFilter;

@Field(() => [NewsFilter], { nullable: true })
@Type(() => NewsFilter)
@ValidateNested({ each: true })
@IsOptional()
and?: NewsFilter[];

@Field(() => [NewsFilter], { nullable: true })
@Type(() => NewsFilter)
@ValidateNested({ each: true })
Expand Down
20 changes: 6 additions & 14 deletions demo/api/src/news/generated/dto/news.input.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,45 @@
// This file has been generated by comet api-generator.
// You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment.
import { BlockInputInterface, DamImageBlock, isBlockInputInterface, IsSlug, PartialType, RootBlockInputScalar } from "@comet/cms-api";
import { Field, InputType } from "@nestjs/graphql";
import { Transform } from "class-transformer";
import { IsDate, IsEnum, IsNotEmpty, IsString, ValidateNested } from "class-validator";

import { NewsContentBlock } from "../../blocks/news-content.block";
import { IsString, IsNotEmpty, ValidateNested, IsDate, IsEnum } from "class-validator";
import { BlockInputInterface, DamImageBlock, IsSlug, PartialType, RootBlockInputScalar, isBlockInputInterface } from "@comet/cms-api";
import { NewsCategory, NewsStatus } from "../../entities/news.entity";

import { NewsContentBlock } from "../../blocks/news-content.block";
@InputType()
export class NewsInput {
@IsNotEmpty()
@IsString()
@IsSlug()
@Field()
slug: string;

@IsNotEmpty()
@IsString()
@Field()
title: string;

@IsNotEmpty()
@IsEnum(NewsStatus)
@Field(() => NewsStatus, { defaultValue: NewsStatus.Active })
@Field(() => NewsStatus, { defaultValue: NewsStatus.Active, })
status: NewsStatus;

@IsNotEmpty()
@IsDate()
@Field()
date: Date;

@IsNotEmpty()
@IsEnum(NewsCategory)
@Field(() => NewsCategory)
category: NewsCategory;

@IsNotEmpty()
@Field(() => RootBlockInputScalar(DamImageBlock))
@Transform(({ value }) => (isBlockInputInterface(value) ? value : DamImageBlock.blockInputFactory(value)), { toClassOnly: true })
@ValidateNested()
image: BlockInputInterface;

@IsNotEmpty()
@Field(() => RootBlockInputScalar(NewsContentBlock))
@Transform(({ value }) => (isBlockInputInterface(value) ? value : NewsContentBlock.blockInputFactory(value)), { toClassOnly: true })
@ValidateNested()
content: BlockInputInterface;
}

@InputType()
export class NewsUpdateInput extends PartialType(NewsInput) {}
export class NewsUpdateInput extends PartialType(NewsInput) {
}
5 changes: 1 addition & 4 deletions demo/api/src/news/generated/dto/news.sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@
import { SortDirection } from "@comet/cms-api";
import { Field, InputType, registerEnumType } from "@nestjs/graphql";
import { IsEnum } from "class-validator";

export enum NewsSortField {
slug = "slug",
title = "title",
status = "status",
date = "date",
category = "category",
createdAt = "createdAt",
updatedAt = "updatedAt",
updatedAt = "updatedAt"
}
registerEnumType(NewsSortField, {
name: "NewsSortField",
});

@InputType()
export class NewsSort {
@Field(() => NewsSortField)
@IsEnum(NewsSortField)
field: NewsSortField;

@Field(() => SortDirection, { defaultValue: SortDirection.ASC })
@IsEnum(SortDirection)
direction: SortDirection = SortDirection.ASC;
Expand Down
7 changes: 3 additions & 4 deletions demo/api/src/news/generated/dto/paginated-news.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// This file has been generated by comet api-generator.
// You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment.
import { PaginatedResponseFactory } from "@comet/cms-api";
import { ObjectType } from "@nestjs/graphql";

import { PaginatedResponseFactory } from "@comet/cms-api";
import { News } from "../../entities/news.entity";

@ObjectType()
export class PaginatedNews extends PaginatedResponseFactory.create(News) {}
export class PaginatedNews extends PaginatedResponseFactory.create(News) {
}
Loading