+19









Abdul Rahman
GitHub
Antoine Moreaux
martmull
Félix Malfait
Baptiste Devessier
Joseph Chiang
Claude
Guillim
Raphaël Bosi
Lucas Bordeau
Marie
Naifer
prastoin
github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions
Thomas Trompette
Etienne
Ajay A Adsule
bosiraphael
Charles Bochet
Marty
Félix Malfait
Charles Bochet
Cursor Agent
Paul Rastoin
Weiko
greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
nitin
65df511179
https://github.com/user-attachments/assets/8593e488-cb00-4fd2-b903-5ba5766e0254 --------- Co-authored-by: Antoine Moreaux <moreaux.antoine@gmail.com> Co-authored-by: martmull <martmull@hotmail.fr> Co-authored-by: Félix Malfait <felix.malfait@gmail.com> Co-authored-by: Baptiste Devessier <baptiste@devessier.fr> Co-authored-by: Joseph Chiang <josephj6802@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Guillim <guillim@users.noreply.github.com> Co-authored-by: Raphaël Bosi <71827178+bosiraphael@users.noreply.github.com> Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com> Co-authored-by: Marie <51697796+ijreilly@users.noreply.github.com> Co-authored-by: Naifer <161821705+omarNaifer12@users.noreply.github.com> Co-authored-by: prastoin <paul@twenty.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions <github-actions@twenty.com> Co-authored-by: Thomas Trompette <thomas.trompette@sfr.fr> Co-authored-by: Etienne <45695613+etiennejouan@users.noreply.github.com> Co-authored-by: Ajay A Adsule <103304466+AjayAdsule@users.noreply.github.com> Co-authored-by: bosiraphael <raphael.bosi@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com> Co-authored-by: Marty <91310557+real-marty@users.noreply.github.com> Co-authored-by: Félix Malfait <felix@twenty.com> Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Paul Rastoin <45004772+prastoin@users.noreply.github.com> Co-authored-by: Weiko <corentin@twenty.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: nitin <142569587+ehconitin@users.noreply.github.com>
171 lines
6.1 KiB
TypeScript
171 lines
6.1 KiB
TypeScript
import { UseGuards } from '@nestjs/common';
|
|
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
import graphqlTypeJson from 'graphql-type-json';
|
|
import { Repository } from 'typeorm';
|
|
|
|
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
|
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
|
|
import { FeatureFlagGuard } from 'src/engine/guards/feature-flag.guard';
|
|
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
|
import { CreateServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/create-serverless-function.input';
|
|
import { ExecuteServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/execute-serverless-function.input';
|
|
import { GetServerlessFunctionSourceCodeInput } from 'src/engine/metadata-modules/serverless-function/dtos/get-serverless-function-source-code.input';
|
|
import { PublishServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/publish-serverless-function.input';
|
|
import { ServerlessFunctionExecutionResultDTO } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto';
|
|
import { ServerlessFunctionIdInput } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-id.input';
|
|
import { ServerlessFunctionDTO } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto';
|
|
import { UpdateServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/update-serverless-function.input';
|
|
import { ServerlessFunctionEntity } from 'src/engine/metadata-modules/serverless-function/serverless-function.entity';
|
|
import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service';
|
|
import { serverlessFunctionGraphQLApiExceptionHandler } from 'src/engine/metadata-modules/serverless-function/utils/serverless-function-graphql-api-exception-handler.utils';
|
|
|
|
@UseGuards(WorkspaceAuthGuard, FeatureFlagGuard)
|
|
@Resolver()
|
|
export class ServerlessFunctionResolver {
|
|
constructor(
|
|
private readonly serverlessFunctionService: ServerlessFunctionService,
|
|
@InjectRepository(ServerlessFunctionEntity, 'core')
|
|
private readonly serverlessFunctionRepository: Repository<ServerlessFunctionEntity>,
|
|
) {}
|
|
|
|
@Query(() => ServerlessFunctionDTO)
|
|
async findOneServerlessFunction(
|
|
@Args('input') { id }: ServerlessFunctionIdInput,
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
) {
|
|
try {
|
|
return await this.serverlessFunctionRepository.findOneOrFail({
|
|
where: {
|
|
id,
|
|
workspaceId,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Query(() => [ServerlessFunctionDTO])
|
|
async findManyServerlessFunctions(
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
) {
|
|
try {
|
|
return await this.serverlessFunctionService.findManyServerlessFunctions({
|
|
workspaceId,
|
|
});
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Query(() => graphqlTypeJson)
|
|
async getAvailablePackages(@Args('input') { id }: ServerlessFunctionIdInput) {
|
|
try {
|
|
return await this.serverlessFunctionService.getAvailablePackages(id);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Query(() => graphqlTypeJson, { nullable: true })
|
|
async getServerlessFunctionSourceCode(
|
|
@Args('input') input: GetServerlessFunctionSourceCodeInput,
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
) {
|
|
try {
|
|
return await this.serverlessFunctionService.getServerlessFunctionSourceCode(
|
|
workspaceId,
|
|
input.id,
|
|
input.version,
|
|
);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Mutation(() => ServerlessFunctionDTO)
|
|
async deleteOneServerlessFunction(
|
|
@Args('input') input: ServerlessFunctionIdInput,
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
) {
|
|
try {
|
|
return await this.serverlessFunctionService.deleteOneServerlessFunction({
|
|
id: input.id,
|
|
workspaceId,
|
|
});
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Mutation(() => ServerlessFunctionDTO)
|
|
async updateOneServerlessFunction(
|
|
@Args('input')
|
|
input: UpdateServerlessFunctionInput,
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
) {
|
|
try {
|
|
return await this.serverlessFunctionService.updateOneServerlessFunction(
|
|
input,
|
|
workspaceId,
|
|
);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Mutation(() => ServerlessFunctionDTO)
|
|
async createOneServerlessFunction(
|
|
@Args('input')
|
|
input: CreateServerlessFunctionInput,
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
) {
|
|
try {
|
|
return await this.serverlessFunctionService.createOneServerlessFunction(
|
|
input,
|
|
workspaceId,
|
|
);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Mutation(() => ServerlessFunctionExecutionResultDTO)
|
|
async executeOneServerlessFunction(
|
|
@Args('input') input: ExecuteServerlessFunctionInput,
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
) {
|
|
try {
|
|
const { id, payload, version } = input;
|
|
|
|
return await this.serverlessFunctionService.executeOneServerlessFunction(
|
|
id,
|
|
workspaceId,
|
|
payload,
|
|
version,
|
|
);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
|
|
@Mutation(() => ServerlessFunctionDTO)
|
|
async publishServerlessFunction(
|
|
@Args('input') input: PublishServerlessFunctionInput,
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
) {
|
|
try {
|
|
const { id } = input;
|
|
|
|
return await this.serverlessFunctionService.publishOneServerlessFunction(
|
|
id,
|
|
workspaceId,
|
|
);
|
|
} catch (error) {
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
}
|
|
}
|
|
}
|