|
|
|
|
@ -5,7 +5,6 @@ import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
|
import graphqlTypeJson from 'graphql-type-json';
|
|
|
|
|
import { Repository } from 'typeorm';
|
|
|
|
|
|
|
|
|
|
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
|
|
|
|
|
import { FeatureFlag } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
|
|
|
|
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
|
|
|
|
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
|
|
|
|
|
@ -19,10 +18,6 @@ import { ServerlessFunctionIdInput } from 'src/engine/metadata-modules/serverles
|
|
|
|
|
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 {
|
|
|
|
|
ServerlessFunctionException,
|
|
|
|
|
ServerlessFunctionExceptionCode,
|
|
|
|
|
} from 'src/engine/metadata-modules/serverless-function/serverless-function.exception';
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
|
|
@ -37,29 +32,12 @@ export class ServerlessFunctionResolver {
|
|
|
|
|
private readonly serverlessFunctionRepository: Repository<ServerlessFunctionEntity>,
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
async checkFeatureFlag(workspaceId: string) {
|
|
|
|
|
const isWorkflowEnabled = await this.featureFlagRepository.findOneBy({
|
|
|
|
|
workspaceId,
|
|
|
|
|
key: FeatureFlagKey.IS_WORKFLOW_ENABLED,
|
|
|
|
|
value: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!isWorkflowEnabled) {
|
|
|
|
|
throw new ServerlessFunctionException(
|
|
|
|
|
`IS_WORKFLOW_ENABLED feature flag is not set to true for this workspace`,
|
|
|
|
|
ServerlessFunctionExceptionCode.FEATURE_FLAG_INVALID,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Query(() => ServerlessFunctionDTO)
|
|
|
|
|
async findOneServerlessFunction(
|
|
|
|
|
@Args('input') { id }: ServerlessFunctionIdInput,
|
|
|
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
await this.checkFeatureFlag(workspaceId);
|
|
|
|
|
|
|
|
|
|
return await this.serverlessFunctionRepository.findOneOrFail({
|
|
|
|
|
where: {
|
|
|
|
|
id,
|
|
|
|
|
@ -76,8 +54,6 @@ export class ServerlessFunctionResolver {
|
|
|
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
await this.checkFeatureFlag(workspaceId);
|
|
|
|
|
|
|
|
|
|
return await this.serverlessFunctionService.findManyServerlessFunctions({
|
|
|
|
|
workspaceId,
|
|
|
|
|
});
|
|
|
|
|
@ -87,13 +63,8 @@ export class ServerlessFunctionResolver {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Query(() => graphqlTypeJson)
|
|
|
|
|
async getAvailablePackages(
|
|
|
|
|
@Args('input') { id }: ServerlessFunctionIdInput,
|
|
|
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
|
|
|
) {
|
|
|
|
|
async getAvailablePackages(@Args('input') { id }: ServerlessFunctionIdInput) {
|
|
|
|
|
try {
|
|
|
|
|
await this.checkFeatureFlag(workspaceId);
|
|
|
|
|
|
|
|
|
|
return await this.serverlessFunctionService.getAvailablePackages(id);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
serverlessFunctionGraphQLApiExceptionHandler(error);
|
|
|
|
|
@ -106,8 +77,6 @@ export class ServerlessFunctionResolver {
|
|
|
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
await this.checkFeatureFlag(workspaceId);
|
|
|
|
|
|
|
|
|
|
return await this.serverlessFunctionService.getServerlessFunctionSourceCode(
|
|
|
|
|
workspaceId,
|
|
|
|
|
input.id,
|
|
|
|
|
@ -124,8 +93,6 @@ export class ServerlessFunctionResolver {
|
|
|
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
await this.checkFeatureFlag(workspaceId);
|
|
|
|
|
|
|
|
|
|
return await this.serverlessFunctionService.deleteOneServerlessFunction({
|
|
|
|
|
id: input.id,
|
|
|
|
|
workspaceId,
|
|
|
|
|
@ -142,8 +109,6 @@ export class ServerlessFunctionResolver {
|
|
|
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
await this.checkFeatureFlag(workspaceId);
|
|
|
|
|
|
|
|
|
|
return await this.serverlessFunctionService.updateOneServerlessFunction(
|
|
|
|
|
input,
|
|
|
|
|
workspaceId,
|
|
|
|
|
@ -160,8 +125,6 @@ export class ServerlessFunctionResolver {
|
|
|
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
await this.checkFeatureFlag(workspaceId);
|
|
|
|
|
|
|
|
|
|
return await this.serverlessFunctionService.createOneServerlessFunction(
|
|
|
|
|
input,
|
|
|
|
|
workspaceId,
|
|
|
|
|
@ -177,7 +140,6 @@ export class ServerlessFunctionResolver {
|
|
|
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
await this.checkFeatureFlag(workspaceId);
|
|
|
|
|
const { id, payload, version } = input;
|
|
|
|
|
|
|
|
|
|
return await this.serverlessFunctionService.executeOneServerlessFunction(
|
|
|
|
|
@ -197,7 +159,6 @@ export class ServerlessFunctionResolver {
|
|
|
|
|
@AuthWorkspace() { id: workspaceId }: Workspace,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
await this.checkFeatureFlag(workspaceId);
|
|
|
|
|
const { id } = input;
|
|
|
|
|
|
|
|
|
|
return await this.serverlessFunctionService.publishOneServerlessFunction(
|
|
|
|
|
|