feat: Implement update step graphQL mutation

This commit is contained in:
Faruk AYDIN
2022-01-06 22:08:46 +03:00
committed by Ali BARIN
parent b6c7ce96c9
commit d25d327ef7
3 changed files with 51 additions and 1 deletions

View 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;

View File

@@ -8,6 +8,7 @@ import deleteConnection from './mutations/delete-connection';
import createFlow from './mutations/create-flow';
import updateFlow from './mutations/update-flow';
import createStep from './mutations/create-step';
import updateStep from './mutations/update-step';
import executeStep from './mutations/execute-step';
import login from './mutations/login';
@@ -23,6 +24,7 @@ const rootMutation = new GraphQLObjectType({
createFlow,
updateFlow,
createStep,
updateStep,
executeStep,
login
}

View File

@@ -29,7 +29,7 @@ class Step extends Base {
appKey: { type: 'string', minLength: 1, maxLength: 255 },
type: { type: "string", enum: ["action", "trigger"] },
connectionId: { type: 'integer' },
parameters: { type: 'object' },
parameters: { type: ['object', null] },
}
}