feat: Implement get flow graphQL query
This commit is contained in:
29
packages/backend/src/graphql/queries/get-flow.ts
Normal file
29
packages/backend/src/graphql/queries/get-flow.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
||||
import Flow from '../../models/flow';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
import flowType from '../types/flow';
|
||||
|
||||
type Params = {
|
||||
id: number
|
||||
}
|
||||
|
||||
const getFlowResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
const flowParams = { user_id: req.currentUser.id, id: params.id }
|
||||
|
||||
const flow = await Flow.query()
|
||||
.withGraphFetched('steps')
|
||||
.findOne(flowParams)
|
||||
.throwIfNotFound();
|
||||
|
||||
return flow;
|
||||
}
|
||||
|
||||
const getFlow = {
|
||||
type: flowType,
|
||||
args: {
|
||||
id: { type: GraphQLNonNull(GraphQLString) },
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => getFlowResolver(params, req)
|
||||
}
|
||||
|
||||
export default getFlow;
|
Reference in New Issue
Block a user