Spike calling Jira with graphQL API

The existing Jira API are all REST API, and the REST API has the problem of over-fetching or multiple requests.

Jira graphQL API about replacing existing REST API.

By checking, in the JiraControl layer, some interface makes multiple calls to the REST API to retrieve the required data. So, in graphQL API, we can call an API to get some required data, reducing the remote call.

Jira provides the functionality of the graphQL API, which provides us with an API to get a variety of data at once and return only the data we need.

Heartbeat’s API /boards/{boardType}/verify

Section titled Heartbeat’s API /boards/{boardType}/verify

Jira API /rest/agile/1.0/board/{boardId} is used, but only projectKey is used in the logic.

Using the graphQL API instead for /rest/agile/1.0/board/{boardId}, as follows:

API:
POST: https://dorametrics.atlassian.net/gateway/api/graphql
Schema:
query queryProjectKey($boardId: ID!){
  boardScope(boardId: $boardId) {
		projectLocation{
			key
		}
	}
}
Query Variables
{
	"boardId": "ari:cloud:jira:c7ae6448-12ae-4811-8176-1b3f45742448:board/2"
}

Heartbeat’s API /boards /{boardType} and /boards /{boardType}/info

Section titled Heartbeat’s API /boards /{boardType} and /boards /{boardType}/info

Using the Jira REST API as follows:

  1. /rest/agile/1.0/board/{boardId}/configuration, to obtain the board.id, board.name, column.name, column.status.id.
  2. /rest/api/2/status/{statusNum}, to get column’s status.untranslatedName, category.key and category.name.
  3. /rest/agile/1.0/board/{boardId}/issue, to get all cards on the board, but some card fields are missing.
  1. Using the graphQL API instead for /rest/agile/1.0/board/{boardId}/configuration and rest/api/2/status/{statusNum}, as follows:
API:
POST: https://dorametrics.atlassian.net/gateway/api/graphql
Schema:
query myboard($boardId: ID!) {
	boardScope(boardId: $boardId) {
		board {
			id
			name
			columns {
				id
				name
				columnStatus {
					status {
						id
						name
						category
					}
				}
			}
		}
	}
}

Query Variables
{
	"boardId": "ari:cloud:jira:c7ae6448-12ae-4811-8176-1b3f45742448:board/2"
}

As we can see, the REST API needs to call the interface twice to get the required value, and graphQL API only needs to call once.

  1. Using the graphQL API instead for /rest/agile/1.0/board/{boardId}/issue, as follows:
API:
POST: https://dorametrics.atlassian.net/gateway/api/graphql
Schema:
query myboard($boardId: ID!){
  boardScope(boardId: $boardId) {
    projectLocation{
        id
        name
        key
      }
		board{
        cards{
					id
					key
					summary
          estimate{
            storyPoints
          }
          parentId
          priority{
            name
          }
          fixVersionsIds
					labels
					activeSprint{
						name
					}
					type{
						name
					}
					assignee{
              name
            }
					status{
						name

					}
        }
      }

  }
}

Query Variables
{
	"boardId": "ari:cloud:jira:c7ae6448-12ae-4811-8176-1b3f45742448:board/2"
}

With this graphQL API replacement, the fields required in the project are the statusCategoryChangeDate, customFields and reporter, which require further investigation.

As you can see from graphQL API above, these three rest apis can be replaced by a single graphQL API, simply by modifying the schema.

There are three other interfaces to the REST API for Jira that do not support graphQL API replacement. as follows:

  1. /rest/api/2/project/{projectIdOrKey}, the graphQL API returns a project.style is TEAM_MANAGED_PROJECT and COMPANY_MANAGED_PROJECT,but we need the project.style is next-gen and classic.

  2. /rest/internal/2/issue/{jiraCardKey}/activityfeed, there is no graphQL API to query history card record was found in the current data.

  3. /rest/api/2/issue/createmeta, this interface looks up the fields of issue types of the project, but currently graphQL provides fields without issue types in the return value of the query project.

Here are three apis you can use to test Jira graphQL API, and we can copy the header from the Jira page to test graphQL API.as follows:

  1. https://dorametrics.atlassian.net/jsw/graphql

  2. https://dorametrics.atlassian.net/rest/gira/1/

  3. https://dorametrics.atlassian.net/gateway/api/graphql. Note: This API is provided by official documentation

https://docs.google.com/spreadsheets/d/1ccERIdeWRN6nlRHb8AaAD8LpdhQyqIw4/edit#gid=1991743326