feat: Implement update step graphQL mutation
This commit is contained in:
48
packages/backend/src/graphql/mutations/update-step.ts
Normal file
48
packages/backend/src/graphql/mutations/update-step.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { GraphQLInt, GraphQLString, GraphQLNonNull } from 'graphql';
|
||||||
|
import Flow from '../../models/flow';
|
||||||
|
import Step from '../../models/step';
|
||||||
|
import flowType from '../types/flow';
|
||||||
|
import stepType from '../types/step';
|
||||||
|
import availableAppsEnumType from '../types/available-apps-enum-type';
|
||||||
|
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
id: number,
|
||||||
|
flowId: number,
|
||||||
|
key: string,
|
||||||
|
appKey: string,
|
||||||
|
connectionId: number
|
||||||
|
}
|
||||||
|
const updateStepResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||||
|
const flow = await Flow.query().findOne({
|
||||||
|
user_id: req.currentUser.id,
|
||||||
|
id: params.flowId
|
||||||
|
}).throwIfNotFound();
|
||||||
|
|
||||||
|
let step = await Step.query().findOne({
|
||||||
|
flow_id: flow.id,
|
||||||
|
id: params.id
|
||||||
|
}).throwIfNotFound();
|
||||||
|
|
||||||
|
step = await step.$query().patchAndFetch({
|
||||||
|
...step,
|
||||||
|
key: params.key,
|
||||||
|
appKey: params.appKey,
|
||||||
|
connectionId: params.connectionId
|
||||||
|
})
|
||||||
|
|
||||||
|
return step;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateStep = {
|
||||||
|
type: stepType,
|
||||||
|
args: {
|
||||||
|
id: { type: GraphQLNonNull(GraphQLInt) },
|
||||||
|
flowId: { type: GraphQLNonNull(GraphQLInt) },
|
||||||
|
key: { type: GraphQLString },
|
||||||
|
appKey: { type: availableAppsEnumType },
|
||||||
|
},
|
||||||
|
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => updateStepResolver(params, req)
|
||||||
|
};
|
||||||
|
|
||||||
|
export default updateStep;
|
@@ -8,6 +8,7 @@ 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 createStep from './mutations/create-step';
|
import createStep from './mutations/create-step';
|
||||||
|
import updateStep from './mutations/update-step';
|
||||||
import executeStep from './mutations/execute-step';
|
import executeStep from './mutations/execute-step';
|
||||||
import login from './mutations/login';
|
import login from './mutations/login';
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ const rootMutation = new GraphQLObjectType({
|
|||||||
createFlow,
|
createFlow,
|
||||||
updateFlow,
|
updateFlow,
|
||||||
createStep,
|
createStep,
|
||||||
|
updateStep,
|
||||||
executeStep,
|
executeStep,
|
||||||
login
|
login
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@ class Step extends Base {
|
|||||||
appKey: { type: 'string', minLength: 1, maxLength: 255 },
|
appKey: { type: 'string', minLength: 1, maxLength: 255 },
|
||||||
type: { type: "string", enum: ["action", "trigger"] },
|
type: { type: "string", enum: ["action", "trigger"] },
|
||||||
connectionId: { type: 'integer' },
|
connectionId: { type: 'integer' },
|
||||||
parameters: { type: 'object' },
|
parameters: { type: ['object', null] },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user