Scaffold empty workflow (#6926)

- Create a workflow version when the user visits an empty workflow.
- If the trigger is not defined yet and the user selects either the
standard object type or the event type first, we automatically select
the first option of the other value. Indeed, every state update is
automatically saved on the backend and we need both standard object and
event types to save the event name.
- Introduces a change in the backend. I removed the assertions that
throw when a workflow version is not complete, that is, when it doesn't
have a defined trigger, which is the case when scaffolding a new
workflow with a first empty workflow version.
- We should keep validating the workflow versions, at least when we
publish them. That should be done in a second step.
This commit is contained in:
Baptiste Devessier
2024-09-12 17:01:10 +02:00
committed by GitHub
parent 3c4168759a
commit 3548751be2
26 changed files with 548 additions and 269 deletions

View File

@ -9,3 +9,11 @@ export interface WorkspaceQueryHookInstance {
payload: ResolverArgs,
): Promise<ResolverArgs>;
}
export interface WorkspaceQueryPostHookInstance {
execute(
authContext: AuthContext,
objectName: string,
payload: unknown[],
): Promise<void>;
}

View File

@ -66,4 +66,25 @@ export class WorkspaceQueryHookStorage {
this.postHookInstances.get(key)?.push(data);
}
getWorkspaceQueryPostHookInstances(
key: WorkspaceQueryHookKey,
): WorkspaceQueryHookData<WorkspaceQueryHookInstance>[] {
const methodName = key.split('.')?.[1] as
| WorkspaceResolverBuilderMethodNames
| undefined;
let wildcardInstances: WorkspaceQueryHookData<WorkspaceQueryHookInstance>[] =
[];
if (!methodName) {
throw new Error(`Can't split workspace query hook key: ${key}`);
}
// Retrive wildcard post-hook instances
if (this.postHookInstances.has(`*.${methodName}`)) {
wildcardInstances = this.postHookInstances.get(`*.${methodName}`)!;
}
return [...wildcardInstances, ...(this.postHookInstances.get(key) ?? [])];
}
}

View File

@ -2,12 +2,13 @@ import { Injectable } from '@nestjs/common';
import merge from 'lodash.merge';
import { Record as IRecord } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface';
import { WorkspaceResolverBuilderMethodNames } from 'src/engine/api/graphql/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
import { WorkspaceQueryHookStorage } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/storage/workspace-query-hook.storage';
import { WorkspaceQueryHookKey } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/decorators/workspace-query-hook.decorator';
import { WorkspaceQueryHookExplorer } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/workspace-query-hook.explorer';
import { WorkspaceQueryHookStorage } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/storage/workspace-query-hook.storage';
import { WorkspacePreQueryHookPayload } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/types/workspace-query-hook.type';
import { WorkspaceQueryHookExplorer } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/workspace-query-hook.explorer';
import { AuthContext } from 'src/engine/core-modules/auth/types/auth-context.type';
@Injectable()
@ -49,4 +50,32 @@ export class WorkspaceQueryHookService {
return payload;
}
public async executePostQueryHooks<
T extends WorkspaceResolverBuilderMethodNames,
Record extends IRecord = IRecord,
>(
authContext: AuthContext,
// TODO: We should allow wildcard for object name
objectName: string,
methodName: T,
payload: Record[],
): Promise<void> {
const key: WorkspaceQueryHookKey = `${objectName}.${methodName}`;
const postHookInstances =
this.workspaceQueryHookStorage.getWorkspaceQueryPostHookInstances(key);
if (!postHookInstances) {
return;
}
for (const postHookInstance of postHookInstances) {
await this.workspaceQueryHookExplorer.handleHook(
[authContext, objectName, payload],
postHookInstance.instance,
postHookInstance.host,
postHookInstance.isRequestScoped,
);
}
}
}

View File

@ -325,6 +325,13 @@ export class WorkspaceQueryRunnerService {
)
)?.records;
await this.workspaceQueryHookService.executePostQueryHooks(
authContext,
objectMetadataItem.nameSingular,
'createMany',
parsedResults,
);
await this.triggerWebhooks<Record>(
parsedResults,
CallWebhookJobsJobOperation.create,