import { UseGuards } from '@nestjs/common'; import { Args, Mutation, Resolver } from '@nestjs/graphql'; import { FileUpload, GraphQLUpload } from 'graphql-upload'; import { JwtAuthGuard } from 'src/engine/guards/jwt.auth.guard'; import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service'; import { ExecuteServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/execute-serverless-function.input'; import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator'; import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity'; import { ServerlessFunctionDto } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto'; import { ServerlessFunctionExecutionResultDTO } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result-d-t.o'; import { serverlessFunctionGraphQLApiExceptionHandler } from 'src/engine/metadata-modules/serverless-function/utils/serverless-function-graphql-api-exception-handler.utils'; @UseGuards(JwtAuthGuard) @Resolver() export class ServerlessFunctionResolver { constructor( private readonly serverlessFunctionService: ServerlessFunctionService, ) {} @Mutation(() => ServerlessFunctionDto) async createOneServerlessFunction( @Args({ name: 'file', type: () => GraphQLUpload }) file: FileUpload, @Args('name', { type: () => String }) name: string, @AuthWorkspace() { id: workspaceId }: Workspace, ) { try { return await this.serverlessFunctionService.createOne( name, workspaceId, file, ); } catch (error) { serverlessFunctionGraphQLApiExceptionHandler(error); } } @Mutation(() => ServerlessFunctionExecutionResultDTO) async executeOneServerlessFunction( @Args() executeServerlessFunctionInput: ExecuteServerlessFunctionInput, @AuthWorkspace() { id: workspaceId }: Workspace, ) { try { const { name, payload } = executeServerlessFunctionInput; return { result: await this.serverlessFunctionService.executeOne( name, workspaceId, payload, ), }; } catch (error) { serverlessFunctionGraphQLApiExceptionHandler(error); } } }