mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -05:00
Address Build Warnings and Cleanup (#707)
* Address build warnings and cleanup * Actual name of who defined the protocol * Remove uneeded detekt supression * GraphQL Before-After cleanup * Lint * Cleanup unused functions * Fix some discrepancies with the 1.5 source api and fix lang exception
This commit is contained in:
@@ -12,15 +12,8 @@ import graphql.schema.DataFetchingEnvironment
|
||||
import org.jetbrains.exposed.sql.Column
|
||||
import org.jetbrains.exposed.sql.Op
|
||||
import org.jetbrains.exposed.sql.SortOrder
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.less
|
||||
import org.jetbrains.exposed.sql.andWhere
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
|
||||
@@ -37,6 +30,7 @@ import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||
import suwayomi.tachidesk.graphql.server.primitives.applyBeforeAfter
|
||||
import suwayomi.tachidesk.graphql.server.primitives.greaterNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
|
||||
@@ -157,21 +151,12 @@ class CategoryQuery {
|
||||
val firstResult = res.firstOrNull()?.get(CategoryTable.id)?.value
|
||||
val lastResult = res.lastOrNull()?.get(CategoryTable.id)?.value
|
||||
|
||||
if (after != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).less(after)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).greater(after)
|
||||
}
|
||||
}
|
||||
} else if (before != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).greater(before)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).less(before)
|
||||
}
|
||||
}
|
||||
}
|
||||
res.applyBeforeAfter(
|
||||
before = before,
|
||||
after = after,
|
||||
orderBy = orderBy ?: CategoryOrderBy.ID,
|
||||
orderByType = orderByType,
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
|
||||
@@ -12,18 +12,11 @@ import graphql.schema.DataFetchingEnvironment
|
||||
import org.jetbrains.exposed.sql.Column
|
||||
import org.jetbrains.exposed.sql.Op
|
||||
import org.jetbrains.exposed.sql.SortOrder
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.less
|
||||
import org.jetbrains.exposed.sql.andWhere
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.queries.ChapterQuery.ChapterOrderBy.ID
|
||||
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.Filter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.FloatFilter
|
||||
@@ -40,6 +33,7 @@ import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||
import suwayomi.tachidesk.graphql.server.primitives.applyBeforeAfter
|
||||
import suwayomi.tachidesk.graphql.server.primitives.greaterNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
|
||||
@@ -241,21 +235,12 @@ class ChapterQuery {
|
||||
val firstResult = res.firstOrNull()?.get(ChapterTable.id)?.value
|
||||
val lastResult = res.lastOrNull()?.get(ChapterTable.id)?.value
|
||||
|
||||
if (after != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ID).less(after)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ID).greater(after)
|
||||
}
|
||||
}
|
||||
} else if (before != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ID).greater(before)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ID).less(before)
|
||||
}
|
||||
}
|
||||
}
|
||||
res.applyBeforeAfter(
|
||||
before = before,
|
||||
after = after,
|
||||
orderBy = orderBy ?: ChapterOrderBy.ID,
|
||||
orderByType = orderByType,
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
|
||||
@@ -13,16 +13,9 @@ import graphql.schema.DataFetchingEnvironment
|
||||
import org.jetbrains.exposed.sql.Column
|
||||
import org.jetbrains.exposed.sql.Op
|
||||
import org.jetbrains.exposed.sql.SortOrder
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.less
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.neq
|
||||
import org.jetbrains.exposed.sql.andWhere
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
|
||||
@@ -38,6 +31,7 @@ import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||
import suwayomi.tachidesk.graphql.server.primitives.applyBeforeAfter
|
||||
import suwayomi.tachidesk.graphql.server.primitives.greaterNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
|
||||
@@ -187,21 +181,12 @@ class ExtensionQuery {
|
||||
val firstResult = res.firstOrNull()?.get(ExtensionTable.pkgName)
|
||||
val lastResult = res.lastOrNull()?.get(ExtensionTable.pkgName)
|
||||
|
||||
if (after != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).less(after)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).greater(after)
|
||||
}
|
||||
}
|
||||
} else if (before != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).greater(before)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).less(before)
|
||||
}
|
||||
}
|
||||
}
|
||||
res.applyBeforeAfter(
|
||||
before = before,
|
||||
after = after,
|
||||
orderBy = orderBy ?: ExtensionOrderBy.PKG_NAME,
|
||||
orderByType = orderByType,
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
|
||||
@@ -12,15 +12,8 @@ import graphql.schema.DataFetchingEnvironment
|
||||
import org.jetbrains.exposed.sql.Column
|
||||
import org.jetbrains.exposed.sql.Op
|
||||
import org.jetbrains.exposed.sql.SortOrder
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.less
|
||||
import org.jetbrains.exposed.sql.andWhere
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
|
||||
@@ -39,6 +32,7 @@ import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||
import suwayomi.tachidesk.graphql.server.primitives.applyBeforeAfter
|
||||
import suwayomi.tachidesk.graphql.server.primitives.greaterNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
|
||||
@@ -245,21 +239,12 @@ class MangaQuery {
|
||||
val firstResult = res.firstOrNull()?.get(MangaTable.id)?.value
|
||||
val lastResult = res.lastOrNull()?.get(MangaTable.id)?.value
|
||||
|
||||
if (after != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).less(after)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).greater(after)
|
||||
}
|
||||
}
|
||||
} else if (before != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).greater(before)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).less(before)
|
||||
}
|
||||
}
|
||||
}
|
||||
res.applyBeforeAfter(
|
||||
before = before,
|
||||
after = after,
|
||||
orderBy = orderBy ?: MangaOrderBy.ID,
|
||||
orderByType = orderByType,
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
|
||||
@@ -12,15 +12,8 @@ import graphql.schema.DataFetchingEnvironment
|
||||
import org.jetbrains.exposed.sql.Column
|
||||
import org.jetbrains.exposed.sql.Op
|
||||
import org.jetbrains.exposed.sql.SortOrder
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.less
|
||||
import org.jetbrains.exposed.sql.andWhere
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.global.model.table.GlobalMetaTable
|
||||
@@ -34,6 +27,7 @@ import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||
import suwayomi.tachidesk.graphql.server.primitives.applyBeforeAfter
|
||||
import suwayomi.tachidesk.graphql.server.primitives.greaterNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
|
||||
@@ -141,21 +135,12 @@ class MetaQuery {
|
||||
val firstResult = res.firstOrNull()?.get(GlobalMetaTable.key)
|
||||
val lastResult = res.lastOrNull()?.get(GlobalMetaTable.key)
|
||||
|
||||
if (after != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).less(after)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).greater(after)
|
||||
}
|
||||
}
|
||||
} else if (before != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).greater(before)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).less(before)
|
||||
}
|
||||
}
|
||||
}
|
||||
res.applyBeforeAfter(
|
||||
before = before,
|
||||
after = after,
|
||||
orderBy = orderBy ?: MetaOrderBy.KEY,
|
||||
orderByType = orderByType,
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
|
||||
@@ -12,15 +12,8 @@ import graphql.schema.DataFetchingEnvironment
|
||||
import org.jetbrains.exposed.sql.Column
|
||||
import org.jetbrains.exposed.sql.Op
|
||||
import org.jetbrains.exposed.sql.SortOrder
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_FIRST
|
||||
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_LAST
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.less
|
||||
import org.jetbrains.exposed.sql.andWhere
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
|
||||
@@ -37,6 +30,7 @@ import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||
import suwayomi.tachidesk.graphql.server.primitives.applyBeforeAfter
|
||||
import suwayomi.tachidesk.graphql.server.primitives.greaterNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
|
||||
@@ -157,21 +151,12 @@ class SourceQuery {
|
||||
val firstResult = res.firstOrNull()?.get(SourceTable.id)?.value
|
||||
val lastResult = res.lastOrNull()?.get(SourceTable.id)?.value
|
||||
|
||||
if (after != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).less(after)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).greater(after)
|
||||
}
|
||||
}
|
||||
} else if (before != null) {
|
||||
res.andWhere {
|
||||
when (orderByType) {
|
||||
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).greater(before)
|
||||
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).less(before)
|
||||
}
|
||||
}
|
||||
}
|
||||
res.applyBeforeAfter(
|
||||
before = before,
|
||||
after = after,
|
||||
orderBy = orderBy ?: SourceOrderBy.ID,
|
||||
orderByType = orderByType,
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
|
||||
@@ -313,7 +313,7 @@ data class StringListFilter(
|
||||
val hasNoneInsensitive: List<String>? = null,
|
||||
) : ListScalarFilter<String, List<String>>
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Suppress("UNCHECKED_CAST", "FINAL_UPPER_BOUND")
|
||||
fun <T : String, S : T?> andFilterWithCompareString(
|
||||
column: Column<S>,
|
||||
filter: StringFilter?,
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package suwayomi.tachidesk.graphql.server
|
||||
|
||||
import com.expediagroup.graphql.generator.execution.GraphQLContext
|
||||
@@ -30,7 +32,9 @@ class TachideskGraphQLContextFactory : GraphQLContextFactory<GraphQLContext, Con
|
||||
// }
|
||||
// }
|
||||
|
||||
fun generateContextMap(request: WsContext): Map<*, Any> = emptyMap<Any, Any>()
|
||||
fun generateContextMap(
|
||||
@Suppress("UNUSED_PARAMETER") request: WsContext,
|
||||
): Map<*, Any> = emptyMap<Any, Any>()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@ import graphql.GraphQL
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.websocket.WsCloseContext
|
||||
import io.javalin.websocket.WsMessageContext
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
@@ -30,6 +31,7 @@ class TachideskGraphQLServer(
|
||||
private val objectMapper = jacksonObjectMapper()
|
||||
private val subscriptionProtocolHandler = ApolloSubscriptionProtocolHandler(contextFactory, subscriptionHandler, objectMapper)
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun handleSubscriptionMessage(context: WsMessageContext) {
|
||||
subscriptionProtocolHandler.handleMessage(context)
|
||||
.map { objectMapper.writeValueAsString(it) }
|
||||
|
||||
@@ -3,11 +3,13 @@ package suwayomi.tachidesk.graphql.server.primitives
|
||||
import org.jetbrains.exposed.dao.id.EntityID
|
||||
import org.jetbrains.exposed.sql.Column
|
||||
import org.jetbrains.exposed.sql.Op
|
||||
import org.jetbrains.exposed.sql.Query
|
||||
import org.jetbrains.exposed.sql.SortOrder
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.less
|
||||
import org.jetbrains.exposed.sql.and
|
||||
import org.jetbrains.exposed.sql.andWhere
|
||||
import org.jetbrains.exposed.sql.or
|
||||
|
||||
interface OrderBy<T> {
|
||||
@@ -36,6 +38,29 @@ fun SortOrder?.maybeSwap(value: Any?): SortOrder {
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> Query.applyBeforeAfter(
|
||||
before: Cursor?,
|
||||
after: Cursor?,
|
||||
orderBy: OrderBy<T>,
|
||||
orderByType: SortOrder?,
|
||||
) {
|
||||
if (after != null) {
|
||||
andWhere {
|
||||
when (orderByType) {
|
||||
SortOrder.DESC, SortOrder.DESC_NULLS_FIRST, SortOrder.DESC_NULLS_LAST -> orderBy.less(after)
|
||||
null, SortOrder.ASC, SortOrder.ASC_NULLS_FIRST, SortOrder.ASC_NULLS_LAST -> orderBy.greater(after)
|
||||
}
|
||||
}
|
||||
} else if (before != null) {
|
||||
andWhere {
|
||||
when (orderByType) {
|
||||
SortOrder.DESC, SortOrder.DESC_NULLS_FIRST, SortOrder.DESC_NULLS_LAST -> orderBy.greater(before)
|
||||
null, SortOrder.ASC, SortOrder.ASC_NULLS_FIRST, SortOrder.ASC_NULLS_LAST -> orderBy.less(before)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmName("greaterNotUniqueIntKey")
|
||||
fun <T : Comparable<T>> greaterNotUnique(
|
||||
column: Column<T>,
|
||||
|
||||
@@ -38,8 +38,8 @@ import suwayomi.tachidesk.graphql.server.toGraphQLContext
|
||||
import suwayomi.tachidesk.server.serverConfig
|
||||
|
||||
/**
|
||||
* Implementation of the `graphql-ws` protocol defined by Apollo
|
||||
* https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
|
||||
* Implementation of the `graphql-transport-ws` protocol defined by Denis Badurina
|
||||
* https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md
|
||||
* ported for Javalin
|
||||
*/
|
||||
class ApolloSubscriptionProtocolHandler(
|
||||
@@ -47,6 +47,10 @@ class ApolloSubscriptionProtocolHandler(
|
||||
private val subscriptionHandler: GraphQLSubscriptionHandler,
|
||||
private val objectMapper: ObjectMapper,
|
||||
) {
|
||||
companion object {
|
||||
private const val UNKNOWN_OPERATION_NAME = "__UNKNOWN__"
|
||||
}
|
||||
|
||||
private val sessionState = ApolloSubscriptionSessionState()
|
||||
private val logger = KotlinLogging.logger {}
|
||||
private val pongMessage = SubscriptionOperationMessage(type = GQL_PONG.type)
|
||||
@@ -54,14 +58,10 @@ class ApolloSubscriptionProtocolHandler(
|
||||
private val acknowledgeMessage = SubscriptionOperationMessage(GQL_CONNECTION_ACK.type)
|
||||
|
||||
private fun getOperationName(payload: Any?): String {
|
||||
val unknownOperationName = "__UNKNOWN__"
|
||||
|
||||
try {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return (payload as Map<String, String>)["operationName"] ?: unknownOperationName
|
||||
} catch (e: Exception) {
|
||||
return unknownOperationName
|
||||
}
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return (payload as? Map<String, String>)
|
||||
.orEmpty()
|
||||
.getOrDefault("operationName", UNKNOWN_OPERATION_NAME)
|
||||
}
|
||||
|
||||
fun handleMessage(context: WsMessageContext): Flow<SubscriptionOperationMessage> {
|
||||
@@ -83,12 +83,12 @@ class ApolloSubscriptionProtocolHandler(
|
||||
|
||||
return try {
|
||||
when (operationMessage.type) {
|
||||
GQL_CONNECTION_INIT.type -> onInit(operationMessage, context)
|
||||
GQL_CONNECTION_INIT.type -> onInit(context)
|
||||
GQL_SUBSCRIBE.type -> startSubscription(operationMessage, context)
|
||||
GQL_COMPLETE.type -> onComplete(operationMessage, context)
|
||||
GQL_COMPLETE.type -> onComplete(operationMessage)
|
||||
GQL_PING.type -> onPing()
|
||||
GQL_PONG.type -> emptyFlow()
|
||||
else -> onUnknownOperation(operationMessage, context)
|
||||
else -> onUnknownOperation(operationMessage)
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
onException(exception)
|
||||
@@ -108,7 +108,6 @@ class ApolloSubscriptionProtocolHandler(
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||
private fun startSubscription(
|
||||
operationMessage: SubscriptionOperationMessage,
|
||||
context: WsContext,
|
||||
@@ -142,7 +141,7 @@ class ApolloSubscriptionProtocolHandler(
|
||||
SubscriptionOperationMessage(type = GQL_NEXT.type, id = operationMessage.id, payload = it)
|
||||
}
|
||||
}
|
||||
.onCompletion { if (it == null) emitAll(onComplete(operationMessage, context)) }
|
||||
.onCompletion { if (it == null) emitAll(onComplete(operationMessage)) }
|
||||
.onStart { sessionState.saveOperation(context, operationMessage, currentCoroutineContext().job) }
|
||||
} catch (exception: Exception) {
|
||||
logger.error("Error running graphql subscription", exception)
|
||||
@@ -152,21 +151,15 @@ class ApolloSubscriptionProtocolHandler(
|
||||
}
|
||||
}
|
||||
|
||||
private fun onInit(
|
||||
operationMessage: SubscriptionOperationMessage,
|
||||
context: WsContext,
|
||||
): Flow<SubscriptionOperationMessage> {
|
||||
saveContext(operationMessage, context)
|
||||
private fun onInit(context: WsContext): Flow<SubscriptionOperationMessage> {
|
||||
saveContext(context)
|
||||
return flowOf(acknowledgeMessage)
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the context and save it for all future messages.
|
||||
*/
|
||||
private fun saveContext(
|
||||
operationMessage: SubscriptionOperationMessage,
|
||||
context: WsContext,
|
||||
) {
|
||||
private fun saveContext(context: WsContext) {
|
||||
runBlocking {
|
||||
val graphQLContext = contextFactory.generateContextMap(context).toGraphQLContext()
|
||||
sessionState.saveContext(context, graphQLContext)
|
||||
@@ -176,10 +169,7 @@ class ApolloSubscriptionProtocolHandler(
|
||||
/**
|
||||
* Called with the publisher has completed on its own.
|
||||
*/
|
||||
private fun onComplete(
|
||||
operationMessage: SubscriptionOperationMessage,
|
||||
context: WsContext,
|
||||
): Flow<SubscriptionOperationMessage> {
|
||||
private fun onComplete(operationMessage: SubscriptionOperationMessage): Flow<SubscriptionOperationMessage> {
|
||||
return sessionState.completeOperation(operationMessage)
|
||||
}
|
||||
|
||||
@@ -192,10 +182,7 @@ class ApolloSubscriptionProtocolHandler(
|
||||
return emptyFlow()
|
||||
}
|
||||
|
||||
private fun onUnknownOperation(
|
||||
operationMessage: SubscriptionOperationMessage,
|
||||
context: WsContext,
|
||||
): Flow<SubscriptionOperationMessage> {
|
||||
private fun onUnknownOperation(operationMessage: SubscriptionOperationMessage): Flow<SubscriptionOperationMessage> {
|
||||
logger.error("Unknown subscription operation $operationMessage")
|
||||
sessionState.completeOperation(operationMessage)
|
||||
return emptyFlow()
|
||||
|
||||
Reference in New Issue
Block a user