feat: Add dynamic fields structure to step arguments
This commit is contained in:
53
packages/backend/src/graphql/queries/get-dynamic-fields.ts
Normal file
53
packages/backend/src/graphql/queries/get-dynamic-fields.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { IDynamicFields, IJSONObject } from '@automatisch/types';
|
||||
import Context from '../../types/express/context';
|
||||
import App from '../../models/app';
|
||||
import globalVariable from '../../helpers/global-variable';
|
||||
|
||||
type Params = {
|
||||
stepId: string;
|
||||
key: string;
|
||||
parameters: IJSONObject;
|
||||
};
|
||||
|
||||
const getDynamicFields = async (
|
||||
_parent: unknown,
|
||||
params: Params,
|
||||
context: Context
|
||||
) => {
|
||||
const step = await context.currentUser
|
||||
.$relatedQuery('steps')
|
||||
.withGraphFetched({
|
||||
connection: true,
|
||||
flow: true,
|
||||
})
|
||||
.findById(params.stepId);
|
||||
|
||||
if (!step) return null;
|
||||
|
||||
const connection = step.connection;
|
||||
|
||||
if (!connection || !step.appKey) return null;
|
||||
|
||||
const app = await App.findOneByKey(step.appKey);
|
||||
const $ = await globalVariable({ connection, app, flow: step.flow, step });
|
||||
|
||||
const command = app.dynamicFields.find(
|
||||
(data: IDynamicFields) => data.key === params.key
|
||||
);
|
||||
|
||||
for (const parameterKey in params.parameters) {
|
||||
const parameterValue = params.parameters[parameterKey];
|
||||
$.step.parameters[parameterKey] = parameterValue;
|
||||
}
|
||||
|
||||
const existingArguments = await step.getSetupFields();
|
||||
const remainingArguments = await command.run($);
|
||||
|
||||
if (remainingArguments.error) {
|
||||
throw new Error(JSON.stringify(remainingArguments.error));
|
||||
}
|
||||
|
||||
return [...existingArguments, ...remainingArguments.data];
|
||||
};
|
||||
|
||||
export default getDynamicFields;
|
@@ -9,6 +9,7 @@ import getExecution from './queries/get-execution';
|
||||
import getExecutions from './queries/get-executions';
|
||||
import getExecutionSteps from './queries/get-execution-steps';
|
||||
import getDynamicData from './queries/get-dynamic-data';
|
||||
import getDynamicFields from './queries/get-dynamic-fields';
|
||||
import getCurrentUser from './queries/get-current-user';
|
||||
import getLicense from './queries/get-license.ee';
|
||||
import healthcheck from './queries/healthcheck';
|
||||
@@ -25,6 +26,7 @@ const queryResolvers = {
|
||||
getExecutions,
|
||||
getExecutionSteps,
|
||||
getDynamicData,
|
||||
getDynamicFields,
|
||||
getCurrentUser,
|
||||
getLicense,
|
||||
healthcheck,
|
||||
|
@@ -28,6 +28,11 @@ type Query {
|
||||
key: String!
|
||||
parameters: JSONObject
|
||||
): JSONObject
|
||||
getDynamicFields(
|
||||
stepId: String!
|
||||
key: String!
|
||||
parameters: JSONObject
|
||||
): [Field]
|
||||
getCurrentUser: User
|
||||
getLicense: GetLicense
|
||||
healthcheck: AppHealth
|
||||
|
Reference in New Issue
Block a user