feat: Add executeFlow graphQL mutation

This commit is contained in:
Faruk AYDIN
2022-02-03 23:49:49 +03:00
committed by Ali BARIN
parent cf08501371
commit 4b69d7f983
2 changed files with 10 additions and 9 deletions

View File

@@ -0,0 +1,37 @@
import { GraphQLString, GraphQLNonNull } from 'graphql';
import { GraphQLJSONObject } from 'graphql-type-json';
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
type Params = {
stepId: string;
data: Record<string, unknown>;
};
const executeStepResolver = async (
params: Params,
req: RequestWithCurrentUser
): Promise<any> => {
const step = await req.currentUser
.$relatedQuery('steps')
.withGraphFetched('connection')
.findOne({
'steps.id': params.stepId,
})
.throwIfNotFound();
const appClass = (await import(`../../apps/${step.appKey}`)).default;
const appInstance = new appClass(step.connection.data);
const data = await appInstance.triggers[step.key].run();
return { data };
};
const executeStep = {
type: GraphQLJSONObject,
args: {
stepId: { type: GraphQLNonNull(GraphQLString) },
},
resolve: (_: any, params: Params, req: RequestWithCurrentUser) =>
executeStepResolver(params, req),
};
export default executeStep;