Switch from v1 to v2 lubrify functions#16
Conversation
| ?.get(0) | ||
| ?.releases | ||
|
|
||
| if (includeIssues) { |
There was a problem hiding this comment.
this skips the issues queries, if needed for performance reasons
| val issues = mutableSetOf<GetIssuesQuery.Issue>() | ||
| val numPages = ids.size / DEFAULT_PAGE_SIZE | ||
| val idsList = ids.toList() | ||
|
|
||
| for (i in 0..numPages) { | ||
| val query = | ||
| GetIssuesQuery(idsList.subList(i * DEFAULT_PAGE_SIZE, (i + 1) * DEFAULT_PAGE_SIZE)) | ||
| val issuesInPage = | ||
| apolloClient.query(query).toFlow().single().data?.issues?.toSet() ?: emptySet() | ||
| issues.addAll(issuesInPage) | ||
| } |
There was a problem hiding this comment.
the ids need to be batched because the query can only handle 100 ids at a time
| val childIssuesIds = mutableSetOf<String>() | ||
| var endCursor: String? = null | ||
| var hasNextPage: Boolean | ||
| fun getEpicsByIds(epicIds: List<String>): List<EpicData> = runBlocking { |
There was a problem hiding this comment.
this change supports grabbing multiple epics in a single query, whereas before we'd have to do x queries for x epics
| val issues = mutableSetOf<GetIssuesQuery.Issue>() | ||
| val numPages = ids.size / DEFAULT_PAGE_SIZE | ||
| val idsList = ids.toList() | ||
|
|
||
| for (i in 0..numPages) { | ||
| val query = | ||
| GetIssuesQuery( | ||
| idsList | ||
| .stream() | ||
| .skip(i * DEFAULT_PAGE_SIZE.toLong()) | ||
| .limit(DEFAULT_PAGE_SIZE.toLong()) | ||
| .toList()) | ||
|
|
||
| val issuesInPage = | ||
| apolloClient.query(query).toFlow().single().data?.issues?.toSet() ?: emptySet() | ||
| issues.addAll(issuesInPage) | ||
| } | ||
|
|
||
| issues |
There was a problem hiding this comment.
handles splitting ids into groups of 100 for the client, so client doesn't have to worry about pagination details and can just pass in the parameters hassle-free
|
|
||
| private fun handleQueryErrors( | ||
| error: com.apollographql.apollo3.api.Error, | ||
| epicIds: List<String> | ||
| ) { | ||
| when (error.message) { | ||
| "Invalid global id: Make sure id is in Base64 format" -> { | ||
| throw IllegalArgumentException(error.message) | ||
| } | ||
|
|
||
| "Resource not found" -> { | ||
| val missingEpicIndex = | ||
| (error.path?.get(1) as? Int) | ||
| ?: throw IllegalArgumentException("Value cannot be converted to Int") | ||
|
|
||
| throw IllegalArgumentException( | ||
| "Failed to retrieve epic with ID: ${epicIds[missingEpicIndex]}") | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
handles errors for the query that retrieves epics. I included this to provide more useful feedback to client if one of their ids causes a problem (wrong id format or id isn't tied to an epic). that way they can more easily troubleshoot problematic ids
This change is necessary because we missed implementing pagination for releases in a previous story. It also includes some performance enhancements.