Skip to content

Add GraphQL query to retrieve timeline events

Vitali Tatarintev requested to merge 344057-timeline-events-graphql-query into master

What does this MR do and why?

Contributes to #344057 (closed)

Provides GraphQL queries to fetch incident management timeline events.

Some taken decisions

  • I've decided not to include Sortable (app/models/concerns/sortable.rb) for now. It requires overriding the simple_sorts method to exclude sorting by name and define custom sorting by occurring_at. We can replace the implementation later when we need it.

  • Tied permissions to an incident (issue). "Read issue" permissions can differ across the project. For example, some issues can be confidential (so do the incidents, because an incident is a type of issue). For such incidents, I think we should have similar reading permissions.

    That also makes it slightly complicated to provide a query with the list of timeline events across the project without specifying the incident ID. For example, if we decide to provide timeline event activities, similar to activities listed on a user's profile page.

Database queries

SELECT "incident_management_timeline_events".*
FROM "incident_management_timeline_events"
WHERE "incident_management_timeline_events"."issue_id" = 25926784
ORDER BY "incident_management_timeline_events"."occurred_at" ASC

https://explain.depesz.com/s/9S1N


SELECT "incident_management_timeline_events".*
FROM "incident_management_timeline_events"
WHERE "incident_management_timeline_events"."issue_id" = 25926784  AND "incident_management_timeline_events"."id" = 1
ORDER BY "incident_management_timeline_events"."occurred_at" ASC

https://explain.depesz.com/s/HcrP

Example GraphQL queries

All the incident's timeline events

query Extract($fullPath: ID!, $incidentId: IssueID!) {
  project(fullPath: $fullPath) {
    incidentManagementTimelineEvents(incidentId: $incidentId) {
      nodes {
        id
        author { id username }
        updatedByUser { id username }
        incident { id title }
        note
        noteHtml
        promotedFromNote { id body }
        editable
        action
        occurredAt
        createdAt
        updatedAt
      }
    }
  }
}

Query variables:


{
  "fullPath": "ck3g/new-playground",
  "incidentId": "gid://gitlab/Issue/507"
}
Single timeline event

query Extract($fullPath: ID!, $incidentId: IssueID!, $id: IncidentManagementTimelineEventID!) {
  project(fullPath: $fullPath) {
    incidentManagementTimelineEvent(incidentId: $incidentId, id: $id) {
      id
      author { id username }
      updatedByUser { id username }
      incident { id title }
      note
      noteHtml
      promotedFromNote { id body }
      editable
      action
      occurredAt
      createdAt
      updatedAt
    }
  }
}

Query variables:


{
  "fullPath": "ck3g/new-playground",
  "incidentId": "gid://gitlab/Issue/507",
  "id": "gid://gitlab/IncidentManagement::TimelineEvent/1"
}

Screenshots

Timeline events list Single timeline event
Screenshot_2021-12-17_at_10.51.36 Screenshot_2021-12-17_at_10.50.15

How to set up and validate locally

  1. Create one or several records of IncidentManagement::TimelineEvent.
  2. Ensure your local environment has GitLab Ultimate.
  3. Open http://localhost:3000/-/graphql-explorer
  4. Use example queries from above.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports