Skip to content

Draft: MR Analytics GraphQL POC

Adam Hegyi requested to merge graphql-mr-analytics-poc into master

What does this MR do?

This MR is PoC to see if we can use GraphQL for the upcoming Merge Request Analytics feature.

You can try it locally by checking out this branch and opening http://localhost:3000/-/graphql-explorer

Data table (list): shows merge request records (paginated)

The simplest query

query {
  project(fullPath: "gitlab-org/gitlab") {
    mergeRequests {
      nodes {
        id,
        title,
        webUrl,
        createdAt
      }
    }
  }
}

Response:

{
  "data": {
    "project": {
      "mergeRequests": {
        "nodes": [
          {
            "id": "gid://gitlab/MergeRequest/35",
            "title": "Deserunt quod dolor nam et et sed architecto voluptatem consequatur adipisci.",
            "webUrl": "http://127.0.0.1:3000/root/yoyoyo/-/merge_requests/4",
            "createdAt": "2020-07-17T14:43:03Z"
          },
          {
            "id": "gid://gitlab/MergeRequest/34",
            "title": "Quaerat quod est neque veniam eum quia tenetur.",
            "webUrl": "http://127.0.0.1:3000/root/yoyoyo/-/merge_requests/3",
            "createdAt": "2020-07-17T14:43:02Z"
          },
          {
            "id": "gid://gitlab/MergeRequest/33",
            "title": "Omnis nemo occaecati saepe unde ipsam distinctio deserunt quisquam.",
            "webUrl": "http://127.0.0.1:3000/root/yoyoyo/-/merge_requests/2",
            "createdAt": "2020-07-17T14:43:01Z"
          },
          {
            "id": "gid://gitlab/MergeRequest/32",
            "title": "Eveniet numquam ut quas sunt ab ad vitae et minima.",
            "webUrl": "http://127.0.0.1:3000/root/yoyoyo/-/merge_requests/1",
            "createdAt": "2020-07-17T14:43:01Z"
          }
        ]
      }
    }
  }
}

Filtering is possible, but will require some work to add all filter options. This example is not working yet:

query {
  project(fullPath: "gitlab-org/gitlab") {
    mergeRequests(sort: "merged_at_desc", labels: "bug", assignee_username: "ahegyi") {
      nodes {
        id,
        title,
        webUrl,
        createdAt,
        commitCount, # need to be implemented
        commentCount # need to be implemented
      }
    }
  }
}

Chart: shows the number of merge requests counted monthly.

Introduce a new entity called mergeRequestAggregate, it shows counts for the 3 months:

query {
  project(fullPath: "root/yoyoyo") {
    id,
    fullPath,
    name,
    mr_aggregate_2020_01: mergeRequestAggregate(mergedAfter: "2020-01-01", mergedBefore: "2020-01-30") {
      count
    }
    mr_aggregate_2020_02: mergeRequestAggregate(mergedAfter: "2020-02-01", mergedBefore: "2020-02-28") {
      count
    }
    mr_aggregate_2020_03: mergeRequestAggregate(mergedAfter: "2020-03-01", mergedBefore: "2020-03-30") {
      count
    }
  }
}

Response:

{
  "data": {
    "project": {
      "id": "gid://gitlab/Project/119",
      "fullPath": "root/yoyoyo",
      "name": "yoyoyo",
      "mr_aggregate_2020_01": {
        "count": "29"
      },
      "mr_aggregate_2020_02": {
        "count": "26"
      },
      "mr_aggregate_2020_03": {
        "count": "15"
      }
    }
  }
}

With additional filtering (not working).

query {
  project(fullPath: "gitlab-org/gitlab") {
    id,
    fullPath,
    name,
    aggregate_2020_01: mergeRequestAggregate(mergedAfter: "2020-01-01", mergedBefore: "2020-01-30", author_username: "ahegyi") {
      count
    }
    aggregate_2020_02: mergeRequestAggregate(mergedAfter: "2020-02-01", mergedBefore: "2020-02-28", author_username: "ahegyi") {
      count
    }
    aggregate_2020_03: mergeRequestAggregate(mergedAfter: "2020-03-01", mergedBefore: "2020-03-30", author_username: "ahegyi") {
      count
    }
  }
}

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Adam Hegyi

Merge request reports