feat: Introduce my tweet trigger with execute step mutation

This commit is contained in:
Faruk AYDIN
2021-11-19 18:21:04 +01:00
committed by Ömer Faruk Aydın
parent 46321f19f4
commit b42cb759a5
5 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { GraphQLString, GraphQLNonNull } from 'graphql';
import App from '../../models/app';
import Connection from '../../models/connection';
import Step from '../../models/step';
import stepType from '../types/step';
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
type Params = {
id: string,
data: object
}
const executeStepResolver = async (params: Params, req: RequestWithCurrentUser) => {
let step = await Step.query().findOne({
id: params.id
})
let connection = await Connection.query().findOne({
id: step.connectionId
})
const appClass = (await import(`../../apps/${step.appKey}`)).default;
const appInstance = new appClass(connection.data);
await appInstance.triggers[step.key].run();
return step;
}
const executeStep = {
type: stepType,
args: {
id: { type: GraphQLNonNull(GraphQLString) }
},
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => executeStepResolver(params, req)
};
export default executeStep;