All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.nemerosa.ontrack.kdsl.connector.graphql.GraphQLConnectorUtils.kt Maven / Gradle / Ivy

There is a newer version: 4.4.5
Show newest version
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