From 4b69d7f98366e95b0116e6401756754e2d43b21d Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Thu, 3 Feb 2022 23:49:49 +0300 Subject: [PATCH] feat: Add executeFlow graphQL mutation --- .../mutations/{execute-step.ts => execute-flow.ts} | 14 +++++++------- packages/backend/src/graphql/root-mutation.ts | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) rename packages/backend/src/graphql/mutations/{execute-step.ts => execute-flow.ts} (74%) diff --git a/packages/backend/src/graphql/mutations/execute-step.ts b/packages/backend/src/graphql/mutations/execute-flow.ts similarity index 74% rename from packages/backend/src/graphql/mutations/execute-step.ts rename to packages/backend/src/graphql/mutations/execute-flow.ts index 2c5ac446..affddfcc 100644 --- a/packages/backend/src/graphql/mutations/execute-step.ts +++ b/packages/backend/src/graphql/mutations/execute-flow.ts @@ -1,9 +1,9 @@ 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'; type Params = { - id: string; + stepId: string; data: Record; }; const executeStepResolver = async ( @@ -14,21 +14,21 @@ const executeStepResolver = async ( .$relatedQuery('steps') .withGraphFetched('connection') .findOne({ - 'steps.id': params.id, + 'steps.id': params.stepId, }) .throwIfNotFound(); const appClass = (await import(`../../apps/${step.appKey}`)).default; 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 = { - type: stepType, + type: GraphQLJSONObject, args: { - id: { type: GraphQLNonNull(GraphQLString) }, + stepId: { type: GraphQLNonNull(GraphQLString) }, }, resolve: (_: any, params: Params, req: RequestWithCurrentUser) => executeStepResolver(params, req), diff --git a/packages/backend/src/graphql/root-mutation.ts b/packages/backend/src/graphql/root-mutation.ts index fa7a8e78..9216406d 100644 --- a/packages/backend/src/graphql/root-mutation.ts +++ b/packages/backend/src/graphql/root-mutation.ts @@ -7,11 +7,12 @@ import verifyConnection from './mutations/verify-connection'; import deleteConnection from './mutations/delete-connection'; import createFlow from './mutations/create-flow'; import updateFlow from './mutations/update-flow'; +import executeFlow from './mutations/execute-flow'; import deleteFlow from './mutations/delete-flow'; import createStep from './mutations/create-step'; import deleteStep from './mutations/delete-step'; import updateStep from './mutations/update-step'; -import executeStep from './mutations/execute-step'; + import login from './mutations/login'; const rootMutation = new GraphQLObjectType({ @@ -29,7 +30,7 @@ const rootMutation = new GraphQLObjectType({ createStep, updateStep, deleteStep, - executeStep, + executeFlow, login, }, });