Add GraphQL query to retrieve timeline events
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 thesimple_sorts
method to exclude sorting byname
and define custom sorting byoccurring_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 |
---|---|
How to set up and validate locally
- Create one or several records of
IncidentManagement::TimelineEvent
. - Ensure your local environment has GitLab Ultimate.
- Open http://localhost:3000/-/graphql-explorer
- 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.
-
I have evaluated the MR acceptance checklist for this MR.