feat: Implement getStepWithTestExecutions query

This commit is contained in:
Faruk AYDIN
2022-02-22 02:04:12 +03:00
committed by Ali BARIN
parent 98864ceadd
commit d139eb8c06
9 changed files with 112 additions and 4 deletions

View File

@@ -0,0 +1,42 @@
import { GraphQLNonNull, GraphQLString, GraphQLList } from 'graphql';
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
import stepType from '../types/step';
type Params = {
stepId: string;
};
const getStepWithTestExecutionsResolver = async (
params: Params,
req: RequestWithCurrentUser
) => {
const step = await req.currentUser
.$relatedQuery('steps')
.findOne({ 'steps.id': params.stepId })
.throwIfNotFound();
const previousStepsWithCurrentStep = await req.currentUser
.$relatedQuery('steps')
.withGraphJoined('executionSteps')
.select('steps.*', 'executionSteps.data_out as output')
.where('flow_id', '=', step.flowId)
.andWhere('position', '<=', step.position)
.distinctOn('executionSteps.step_id')
.orderBy([
'executionSteps.step_id',
{ column: 'executionSteps.created_at', order: 'desc' },
]);
return previousStepsWithCurrentStep;
};
const getStepWithTestExecutions = {
type: GraphQLList(stepType),
args: {
stepId: { type: GraphQLNonNull(GraphQLString) },
},
resolve: (_: any, params: Params, req: RequestWithCurrentUser) =>
getStepWithTestExecutionsResolver(params, req),
};
export default getStepWithTestExecutions;