Spike calling Jira with graphQL API
Current situation
Section titled Current situationThe existing Jira API are all REST API, and the REST API has the problem of over-fetching or multiple requests.
Expect
Section titled ExpectJira graphQL API about replacing existing REST API.
Scope of impact
Section titled Scope of impactBy 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.
Solutions
Section titled SolutionsJira 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.
Example
Section titled ExampleHeartbeat’s API /boards/{boardType}/verify
Section titled Heartbeat’s API /boards/{boardType}/verifyJira API /rest/agile/1.0/board/{boardId}
is used, but only projectKey
is used in the logic.
Solution
Section titled SolutionUsing 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}/infoUsing the Jira REST API as follows:
/rest/agile/1.0/board/{boardId}/configuration
, to obtain theboard.id
,board.name
,column.name
,column.status.id
./rest/api/2/status/{statusNum}
, to get column’sstatus.untranslatedName
,category.key
andcategory.name
./rest/agile/1.0/board/{boardId}/issue
, to get allcards
on the board, but some card fields are missing.
Solution
Section titled Solution- Using the graphQL API instead for
/rest/agile/1.0/board/{boardId}/configuration
andrest/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.
- 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.
Question
Section titled QuestionThere are three other interfaces to the REST API for Jira that do not support graphQL API replacement. as follows:
-
/rest/api/2/project/{projectIdOrKey}
, the graphQL API returns aproject.style
isTEAM_MANAGED_PROJECT
andCOMPANY_MANAGED_PROJECT
,but we need theproject.style
isnext-gen
andclassic
. -
/rest/internal/2/issue/{jiraCardKey}/activityfeed
, there is no graphQL API to query history card record was found in the current data. -
/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.
Test Jira graphQL API
Section titled Test Jira graphQL APIHere 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:
-
https://dorametrics.atlassian.net/gateway/api/graphql. Note: This API is provided by official documentation
Field correspondence
Section titled Field correspondencehttps://docs.google.com/spreadsheets/d/1ccERIdeWRN6nlRHb8AaAD8LpdhQyqIw4/edit#gid=1991743326