feat: add updateFlow mutation

This commit is contained in:
Ali BARIN
2021-12-19 19:14:11 +01:00
parent d06ce4958e
commit ede68b2af2
5 changed files with 44 additions and 2 deletions

View File

@@ -0,0 +1,33 @@
import { GraphQLInt, GraphQLString, GraphQLNonNull } from 'graphql';
import Flow from '../../models/flow';
import flowType from '../types/flow';
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
type Params = {
id: string,
data: object
}
const updateFlowResolver = async (params: Params, req: RequestWithCurrentUser) => {
let flow = await Flow.query().findOne({
user_id: req.currentUser.id,
id: params.id
}).throwIfNotFound();
flow = await flow.$query().patchAndFetch({
...flow,
...params
})
return flow;
}
const updateFlow = {
type: flowType,
args: {
id: { type: GraphQLNonNull(GraphQLInt) },
name: { type: GraphQLNonNull(GraphQLString) }
},
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => updateFlowResolver(params, req)
};
export default updateFlow;

View File

@@ -6,6 +6,7 @@ import resetConnection from './mutations/reset-connection';
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 createStep from './mutations/create-step';
import executeStep from './mutations/execute-step';
@@ -19,6 +20,7 @@ const rootMutation = new GraphQLObjectType({
verifyConnection,
deleteConnection,
createFlow,
updateFlow,
createStep,
executeStep
}