Skip to content

Mock Api for custom statuses

Abhilash Kotte requested to merge akotte/add-mock-graphql-api-for-statuses into master

What does this MR do and why?

  1. Adds CustomStatus widget to TASK work item type
  2. Exposes CustomStatus widget via GraphQL using mock data
  3. Exposes allowedCustomStatuses field via GraphQl for project, namespace, group, and widgetDefinition

Issue: #498392 (closed)

Note Used CustomStatus as widget name based on #498392 (comment 2280126525)

Migrations

`bundle exec rake db:migrate:up:main VERSION=20250103061005`
main: == [advisory_lock_connection] object_id: 131000, pg_backend_pid: 92454
main: == 20250103061005 AddCustomStatusWidgetToWorkItemTypes: migrating =============
main: == 20250103061005 AddCustomStatusWidgetToWorkItemTypes: migrated (0.0391s) ====

main: == [advisory_lock_connection] object_id: 131000, pg_backend_pid: 92454
`bundle exec rake db:migrate:down:main VERSION=20250103061005`
main: == [advisory_lock_connection] object_id: 131000, pg_backend_pid: 91957
main: == 20250103061005 AddCustomStatusWidgetToWorkItemTypes: reverting =============
main: == 20250103061005 AddCustomStatusWidgetToWorkItemTypes: reverted (0.0398s) ====

main: == [advisory_lock_connection] object_id: 131000, pg_backend_pid: 91957
`bundle exec rake db:migrate:up:ci VERSION=20250103061005`
ci: == [advisory_lock_connection] object_id: 131000, pg_backend_pid: 93097
ci: == 20250103061005 AddCustomStatusWidgetToWorkItemTypes: reverting =============
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_internal, :gitlab_shared].
ci: == 20250103061005 AddCustomStatusWidgetToWorkItemTypes: reverted (0.0093s) ====

ci: == [advisory_lock_connection] object_id: 131000, pg_backend_pid: 93097
`bundle exec rake db:migrate:down:ci VERSION=20250103061005`
ci: == [advisory_lock_connection] object_id: 131000, pg_backend_pid: 93572
ci: == 20250103061005 AddCustomStatusWidgetToWorkItemTypes: migrating =============
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_internal, :gitlab_shared].
ci: == 20250103061005 AddCustomStatusWidgetToWorkItemTypes: migrated (0.0181s) ====

ci: == [advisory_lock_connection] object_id: 131000, pg_backend_pid: 93572

GraphQL

CustomStatus Widget

Request
query namespaceWorkItemTypes($fullPath: ID!, $iid: String!) {
  workspace: namespace(fullPath: $fullPath) {
    id
    workItem(iid: $iid) {
      widgets{
        type
        ... on WorkItemWidgetCustomStatus {
          id
          name
          iconName
        }
      }
    }
  }
}
Response
{
  "data": {
    "workspace": {
      "id": "gid://gitlab/Namespaces::ProjectNamespace/34",
      "workItem": {
        "widgets": [
          {
            "type": "ASSIGNEES"
          },
          {
            "type": "AWARD_EMOJI"
          },
          {
            "type": "CRM_CONTACTS"
          },
          {
            "type": "CURRENT_USER_TODOS"
          },
          {
            "type": "DESCRIPTION"
          },
          {
            "type": "DEVELOPMENT"
          },
          {
            "type": "HIERARCHY"
          },
          {
            "type": "ITERATION"
          },
          {
            "type": "LABELS"
          },
          {
            "type": "LINKED_ITEMS"
          },
          {
            "type": "MILESTONE"
          },
          {
            "type": "NOTES"
          },
          {
            "type": "NOTIFICATIONS"
          },
          {
            "type": "PARTICIPANTS"
          },
          {
            "type": "START_AND_DUE_DATE"
          },
          {
            "type": "TIME_TRACKING"
          },
          {
            "type": "WEIGHT"
          },
          {
            "type": "CUSTOM_STATUS",
            "id": "gid://gitlab/WorkItems::Widgets::CustomStatus/10",
            "name": "Custom Status",
            "iconName": "custom_status icon"
          }
        ]
      },
      "__typename": "Namespace"
    }
  },
  "correlationId": "01JGNTBGZ3B6CGT2X5TC8PAXS0"
}

WidgetDefinition

Request
query namespaceWorkItemTypes($fullPath: ID!, $name: IssueType) {
  workspace: namespace(fullPath: $fullPath) {
    id
    workItemTypes(name: $name) {
      nodes {
        id
        name
        widgetDefinitions {
          type
          ... on WorkItemWidgetDefinitionCustomStatus {
            allowedCustomStatuses {
             nodes {
              id
              name
              iconName
            }
            }
          }
          
        }
        
        __typename
      }
      __typename
    }
    __typename
  }
}
Response
{
  "data": {
    "workspace": {
      "id": "gid://gitlab/Namespaces::ProjectNamespace/34",
      "workItemTypes": {
        "nodes": [
          {
            "id": "gid://gitlab/WorkItems::Type/5",
            "name": "Task",
            "widgetDefinitions": [
              {
                "type": "ASSIGNEES"
              },
              {
                "type": "AWARD_EMOJI"
              },
              {
                "type": "CRM_CONTACTS"
              },
              {
                "type": "CURRENT_USER_TODOS"
              },
              {
                "type": "DESCRIPTION"
              },
              {
                "type": "DEVELOPMENT"
              },
              {
                "type": "HIERARCHY"
              },
              {
                "type": "ITERATION"
              },
              {
                "type": "LABELS"
              },
              {
                "type": "LINKED_ITEMS"
              },
              {
                "type": "MILESTONE"
              },
              {
                "type": "NOTES"
              },
              {
                "type": "NOTIFICATIONS"
              },
              {
                "type": "PARTICIPANTS"
              },
              {
                "type": "START_AND_DUE_DATE"
              },
              {
                "type": "TIME_TRACKING"
              },
              {
                "type": "WEIGHT"
              },
              {
                "type": "CUSTOM_STATUS",
                "allowedCustomStatuses": {
                  "nodes": [
                    {
                      "id": "gid://gitlab/WorkItems::Widgets::CustomStatus/10",
                      "name": "Custom Status",
                      "iconName": "custom_status icon"
                    },
                    {
                      "id": "gid://gitlab/WorkItems::Widgets::CustomStatus/10",
                      "name": "Custom Status",
                      "iconName": "custom_status icon"
                    }
                  ]
                }
              }
            ],
            "__typename": "WorkItemType"
          }
        ],
        "__typename": "WorkItemTypeConnection"
      },
      "__typename": "Namespace"
    }
  },
  "correlationId": "01JGNTDGTZPVY6G7G8DKN3ZM0S"
}

Namespace Level

Request
query namespaceWorkItemTypes($fullPath: ID!) {
  workspace: namespace(fullPath: $fullPath) {
    id
    allowedCustomStatuses {
      nodes {
        id
        name
        iconName
      }
    }
    __typename
  }
}
Response
{
  "data": {
    "workspace": {
      "id": "gid://gitlab/Namespaces::ProjectNamespace/34",
      "allowedCustomStatuses": {
        "nodes": [
          {
            "id": "gid://gitlab/WorkItems::Widgets::CustomStatus/10",
            "name": "Custom Status",
            "iconName": "custom_status icon"
          },
          {
            "id": "gid://gitlab/WorkItems::Widgets::CustomStatus/10",
            "name": "Custom Status",
            "iconName": "custom_status icon"
          }
        ]
      },
      "__typename": "Namespace"
    }
  },
  "correlationId": "01JGNTMW1QWR7ADYHM5FGC54C4"
}

Project Level

Request
query projectWorkItemTypes($fullPath: ID!) {
  workspace: project(fullPath: $fullPath) {
    id
    allowedCustomStatuses {
      nodes {
        id
        name
        iconName
      }
    }
    __typename
  }
}
Response
{
  "data": {
    "workspace": {
      "id": "gid://gitlab/Project/7",
      "allowedCustomStatuses": {
        "nodes": [
          {
            "id": "gid://gitlab/WorkItems::Widgets::CustomStatus/10",
            "name": "Custom Status",
            "iconName": "custom_status icon"
          },
          {
            "id": "gid://gitlab/WorkItems::Widgets::CustomStatus/10",
            "name": "Custom Status",
            "iconName": "custom_status icon"
          }
        ]
      },
      "__typename": "Project"
    }
  },
  "correlationId": "01JGNTREPYW8RV9CZZEMB8ZC00"
}

Group Level

Request
query groupWorkItemTypes($fullPath: ID!) {
  workspace: group(fullPath: $fullPath) {
    id
    allowedCustomStatuses {
      nodes {
        id
        name
        iconName
      }
    }
    __typename
  }
}
Response
{
  "data": {
    "workspace": {
      "id": "gid://gitlab/Group/33",
      "allowedCustomStatuses": {
        "nodes": [
          {
            "id": "gid://gitlab/WorkItems::Widgets::CustomStatus/10",
            "name": "Custom Status",
            "iconName": "custom_status icon"
          },
          {
            "id": "gid://gitlab/WorkItems::Widgets::CustomStatus/10",
            "name": "Custom Status",
            "iconName": "custom_status icon"
          }
        ]
      },
      "__typename": "Group"
    }
  },
  "correlationId": "01JGNTVSGS3PF0W4EKMJVYD5MG"
}

How to set up and validate locally

  1. Run all migrations - bundle exec rake db:migrate
  2. Fire up WorkItemQuery to get widgets and verify the new widget is only available for TASK types
  3. Run all the requests mentioned above and see the response is as expected.
Edited by Abhilash Kotte

Merge request reports

Loading