net.nemerosa.ontrack.kdsl.connector.graphql.GraphQLConnectorUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ontrack-kdsl Show documentation
Show all versions of ontrack-kdsl Show documentation
Ontrack module: ontrack-kdsl
package net.nemerosa.ontrack.kdsl.connector.graphql
import net.nemerosa.ontrack.kdsl.connector.graphql.schema.fragment.PageInfoContent
import net.nemerosa.ontrack.kdsl.connector.support.PaginatedList
import net.nemerosa.ontrack.kdsl.connector.support.emptyPaginatedList
fun T?.checkData(
code: (T) -> R,
) = if (this != null) {
val r = code(this)
r ?: throw GraphQLClientException("No data node was returned")
} else {
throw GraphQLClientException("No data was returned")
}
fun T.paginate(
pageInfo: (T) -> PageInfoContent?,
pageItems: (T) -> List?,
): PaginatedList {
val items = pageItems(this)
return if (items == null) {
emptyPaginatedList()
} else {
PaginatedList(
items = items,
)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy