All files / ee/app/assets/javascripts/analytics/merge_request_analytics/graphql throughput_chart_query_builder.js

85.71% Statements 6/7
25% Branches 1/4
100% Functions 2/2
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58                            61x   61x   61x 243x       243x                               61x                                    
import { gql } from '@apollo/client/core';
import { computeMonthRangeData } from '../utils';
 
/**
 * A GraphQL query building function which accepts a
 * startDate and endDate, returning a parsed query string
 * which nests sub queries for each individual month.
 *
 * @param {Date} startDate the startDate for the data range
 * @param {Date} endDate the endDate for the data range
 *
 * @return {String} the parsed GraphQL query string
 */
export default (startDate = null, endDate = null) => {
  const monthData = computeMonthRangeData(startDate, endDate);
 
  Iif (!monthData.length) return '';
 
  const computedMonthData = monthData.map((value) => {
    const { year, month, mergedAfter, mergedBefore } = value;
 
    // first: 0 is an optimization which makes sure we don't load merge request objects into memory (backend).
    // Currently when requesting counts we also load the first 100 records (preloader problem).
    return `
      ${month}_${year}: mergeRequests(
        first: 0,
        mergedBefore: "${mergedBefore}",
        mergedAfter: "${mergedAfter}",
        labels: $labels,
        authorUsername: $authorUsername,
        assigneeUsername: $assigneeUsername,
        milestoneTitle: $milestoneTitle,
        sourceBranches: $sourceBranches,
        targetBranches: $targetBranches
        not: { labels: $notLabels, milestoneTitle: $notMilestoneTitle }
      ) { count, totalTimeToMerge }
    `;
  });
 
  return gql`
    query(
      $fullPath: ID!,
      $labels: [String!],
      $authorUsername: String,
      $assigneeUsername: String,
      $milestoneTitle: String,
      $sourceBranches: [String!],
      $targetBranches: [String!],
      $notLabels: [String!],
      $notMilestoneTitle: String
    ) {
      throughputChartData: project(fullPath: $fullPath) {
        ${computedMonthData}
      }
    }
  `;
};