feat: Add executeFlow graphQL mutation
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||||
import stepType from '../types/step';
|
import { GraphQLJSONObject } from 'graphql-type-json';
|
||||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
id: string;
|
stepId: string;
|
||||||
data: Record<string, unknown>;
|
data: Record<string, unknown>;
|
||||||
};
|
};
|
||||||
const executeStepResolver = async (
|
const executeStepResolver = async (
|
||||||
@@ -14,21 +14,21 @@ const executeStepResolver = async (
|
|||||||
.$relatedQuery('steps')
|
.$relatedQuery('steps')
|
||||||
.withGraphFetched('connection')
|
.withGraphFetched('connection')
|
||||||
.findOne({
|
.findOne({
|
||||||
'steps.id': params.id,
|
'steps.id': params.stepId,
|
||||||
})
|
})
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
const appClass = (await import(`../../apps/${step.appKey}`)).default;
|
const appClass = (await import(`../../apps/${step.appKey}`)).default;
|
||||||
const appInstance = new appClass(step.connection.data);
|
const appInstance = new appClass(step.connection.data);
|
||||||
await appInstance.triggers[step.key].run();
|
const data = await appInstance.triggers[step.key].run();
|
||||||
|
|
||||||
return step;
|
return { data };
|
||||||
};
|
};
|
||||||
|
|
||||||
const executeStep = {
|
const executeStep = {
|
||||||
type: stepType,
|
type: GraphQLJSONObject,
|
||||||
args: {
|
args: {
|
||||||
id: { type: GraphQLNonNull(GraphQLString) },
|
stepId: { type: GraphQLNonNull(GraphQLString) },
|
||||||
},
|
},
|
||||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) =>
|
resolve: (_: any, params: Params, req: RequestWithCurrentUser) =>
|
||||||
executeStepResolver(params, req),
|
executeStepResolver(params, req),
|
@@ -7,11 +7,12 @@ import verifyConnection from './mutations/verify-connection';
|
|||||||
import deleteConnection from './mutations/delete-connection';
|
import deleteConnection from './mutations/delete-connection';
|
||||||
import createFlow from './mutations/create-flow';
|
import createFlow from './mutations/create-flow';
|
||||||
import updateFlow from './mutations/update-flow';
|
import updateFlow from './mutations/update-flow';
|
||||||
|
import executeFlow from './mutations/execute-flow';
|
||||||
import deleteFlow from './mutations/delete-flow';
|
import deleteFlow from './mutations/delete-flow';
|
||||||
import createStep from './mutations/create-step';
|
import createStep from './mutations/create-step';
|
||||||
import deleteStep from './mutations/delete-step';
|
import deleteStep from './mutations/delete-step';
|
||||||
import updateStep from './mutations/update-step';
|
import updateStep from './mutations/update-step';
|
||||||
import executeStep from './mutations/execute-step';
|
|
||||||
import login from './mutations/login';
|
import login from './mutations/login';
|
||||||
|
|
||||||
const rootMutation = new GraphQLObjectType({
|
const rootMutation = new GraphQLObjectType({
|
||||||
@@ -29,7 +30,7 @@ const rootMutation = new GraphQLObjectType({
|
|||||||
createStep,
|
createStep,
|
||||||
updateStep,
|
updateStep,
|
||||||
deleteStep,
|
deleteStep,
|
||||||
executeStep,
|
executeFlow,
|
||||||
login,
|
login,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user