mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-03 19:04:39 -05:00
Revert "Support sending floats" and convert DoubleFilter to FloatFilter (#1747)
* Revert "[#1739] Support sending floats (#1740)"
This reverts commit c1f2aae90d.
Closes #1746
* Use `DoubleFilter` for GQL interface, convert to `FloatFilter`
Closes #1739 (again)
This commit is contained in:
@@ -20,8 +20,8 @@ import org.jetbrains.exposed.sql.selectAll
|
|||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
|
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
|
||||||
|
import suwayomi.tachidesk.graphql.queries.filter.DoubleFilter
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.Filter
|
import suwayomi.tachidesk.graphql.queries.filter.Filter
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.FloatFilter
|
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.HasGetOp
|
import suwayomi.tachidesk.graphql.queries.filter.HasGetOp
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.IntFilter
|
import suwayomi.tachidesk.graphql.queries.filter.IntFilter
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.LongFilter
|
import suwayomi.tachidesk.graphql.queries.filter.LongFilter
|
||||||
@@ -158,7 +158,7 @@ class ChapterQuery {
|
|||||||
val url: StringFilter? = null,
|
val url: StringFilter? = null,
|
||||||
val name: StringFilter? = null,
|
val name: StringFilter? = null,
|
||||||
val uploadDate: LongFilter? = null,
|
val uploadDate: LongFilter? = null,
|
||||||
val chapterNumber: FloatFilter? = null,
|
val chapterNumber: DoubleFilter? = null,
|
||||||
val scanlator: StringFilter? = null,
|
val scanlator: StringFilter? = null,
|
||||||
val mangaId: IntFilter? = null,
|
val mangaId: IntFilter? = null,
|
||||||
val isRead: BooleanFilter? = null,
|
val isRead: BooleanFilter? = null,
|
||||||
@@ -181,7 +181,7 @@ class ChapterQuery {
|
|||||||
andFilterWithCompareString(ChapterTable.url, url),
|
andFilterWithCompareString(ChapterTable.url, url),
|
||||||
andFilterWithCompareString(ChapterTable.name, name),
|
andFilterWithCompareString(ChapterTable.name, name),
|
||||||
andFilterWithCompare(ChapterTable.date_upload, uploadDate),
|
andFilterWithCompare(ChapterTable.date_upload, uploadDate),
|
||||||
andFilterWithCompare(ChapterTable.chapter_number, chapterNumber),
|
andFilterWithCompare(ChapterTable.chapter_number, chapterNumber?.toFloatFilter()),
|
||||||
andFilterWithCompareString(ChapterTable.scanlator, scanlator),
|
andFilterWithCompareString(ChapterTable.scanlator, scanlator),
|
||||||
andFilterWithCompareEntity(ChapterTable.manga, mangaId),
|
andFilterWithCompareEntity(ChapterTable.manga, mangaId),
|
||||||
andFilterWithCompare(ChapterTable.isRead, isRead),
|
andFilterWithCompare(ChapterTable.isRead, isRead),
|
||||||
|
|||||||
@@ -304,7 +304,26 @@ data class DoubleFilter(
|
|||||||
override val lessThanOrEqualTo: Double? = null,
|
override val lessThanOrEqualTo: Double? = null,
|
||||||
override val greaterThan: Double? = null,
|
override val greaterThan: Double? = null,
|
||||||
override val greaterThanOrEqualTo: Double? = null,
|
override val greaterThanOrEqualTo: Double? = null,
|
||||||
) : ComparableScalarFilter<Double>
|
) : ComparableScalarFilter<Double> {
|
||||||
|
fun toFloatFilter(): FloatFilter =
|
||||||
|
FloatFilter(
|
||||||
|
isNull = isNull,
|
||||||
|
equalTo = equalTo?.toFloat(),
|
||||||
|
notEqualTo = notEqualTo?.toFloat(),
|
||||||
|
notEqualToAll = notEqualToAll?.map { it.toFloat() },
|
||||||
|
notEqualToAny = notEqualToAny?.map { it.toFloat() },
|
||||||
|
distinctFrom = distinctFrom?.toFloat(),
|
||||||
|
distinctFromAll = distinctFromAll?.map { it.toFloat() },
|
||||||
|
distinctFromAny = distinctFromAny?.map { it.toFloat() },
|
||||||
|
notDistinctFrom = notDistinctFrom?.toFloat(),
|
||||||
|
`in` = `in`?.map { it.toFloat() },
|
||||||
|
notIn = notIn?.map { it.toFloat() },
|
||||||
|
lessThan = lessThan?.toFloat(),
|
||||||
|
lessThanOrEqualTo = lessThanOrEqualTo?.toFloat(),
|
||||||
|
greaterThan = greaterThan?.toFloat(),
|
||||||
|
greaterThanOrEqualTo = greaterThanOrEqualTo?.toFloat(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
data class StringFilter(
|
data class StringFilter(
|
||||||
override val isNull: Boolean? = null,
|
override val isNull: Boolean? = null,
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ import suwayomi.tachidesk.graphql.queries.UpdateQuery
|
|||||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.GraphQLCursor
|
import suwayomi.tachidesk.graphql.server.primitives.GraphQLCursor
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.GraphQLDurationAsString
|
import suwayomi.tachidesk.graphql.server.primitives.GraphQLDurationAsString
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.GraphQLFloatAsDouble
|
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.GraphQLLongAsString
|
import suwayomi.tachidesk.graphql.server.primitives.GraphQLLongAsString
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.GraphQLUpload
|
import suwayomi.tachidesk.graphql.server.primitives.GraphQLUpload
|
||||||
import suwayomi.tachidesk.graphql.subscriptions.DownloadSubscription
|
import suwayomi.tachidesk.graphql.subscriptions.DownloadSubscription
|
||||||
@@ -65,7 +64,6 @@ class CustomSchemaGeneratorHooks : FlowSubscriptionSchemaGeneratorHooks() {
|
|||||||
override fun willGenerateGraphQLType(type: KType): GraphQLType? =
|
override fun willGenerateGraphQLType(type: KType): GraphQLType? =
|
||||||
when (type.classifier as? KClass<*>) {
|
when (type.classifier as? KClass<*>) {
|
||||||
Long::class -> GraphQLLongAsString // encode to string for JS
|
Long::class -> GraphQLLongAsString // encode to string for JS
|
||||||
Float::class -> GraphQLFloatAsDouble // encode float as double
|
|
||||||
Duration::class -> GraphQLDurationAsString // encode Duration as ISO-8601 string
|
Duration::class -> GraphQLDurationAsString // encode Duration as ISO-8601 string
|
||||||
Cursor::class -> GraphQLCursor
|
Cursor::class -> GraphQLCursor
|
||||||
UploadedFile::class -> GraphQLUpload
|
UploadedFile::class -> GraphQLUpload
|
||||||
|
|||||||
@@ -1,132 +0,0 @@
|
|||||||
package suwayomi.tachidesk.graphql.server.primitives
|
|
||||||
|
|
||||||
import graphql.GraphQLContext
|
|
||||||
import graphql.execution.CoercedVariables
|
|
||||||
import graphql.language.FloatValue
|
|
||||||
import graphql.language.Value
|
|
||||||
import graphql.scalar.CoercingUtil
|
|
||||||
import graphql.schema.Coercing
|
|
||||||
import graphql.schema.CoercingParseLiteralException
|
|
||||||
import graphql.schema.CoercingParseValueException
|
|
||||||
import graphql.schema.CoercingSerializeException
|
|
||||||
import graphql.schema.GraphQLScalarType
|
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
val GraphQLFloatAsDouble: GraphQLScalarType =
|
|
||||||
GraphQLScalarType
|
|
||||||
.newScalar()
|
|
||||||
.name(
|
|
||||||
"Float32",
|
|
||||||
).description("32-bit float aka kotlin.lang.Float")
|
|
||||||
.coercing(GraphqlActualFloatCoercing())
|
|
||||||
.build()
|
|
||||||
|
|
||||||
private class GraphqlActualFloatCoercing : Coercing<Float, Double> {
|
|
||||||
private fun toDoubleImpl(input: Any): Double? =
|
|
||||||
when (input) {
|
|
||||||
is Float -> input.toDouble()
|
|
||||||
is Double -> input
|
|
||||||
is Int -> input.toDouble()
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseValueImpl(
|
|
||||||
input: Any,
|
|
||||||
locale: Locale,
|
|
||||||
): Float =
|
|
||||||
when (input) {
|
|
||||||
is Int -> input.toFloat()
|
|
||||||
is Double -> input.toFloat()
|
|
||||||
else -> throw CoercingParseValueException(
|
|
||||||
CoercingUtil.i18nMsg(
|
|
||||||
locale,
|
|
||||||
"Float.unexpectedRawValueType",
|
|
||||||
CoercingUtil.typeName(input),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseLiteralImpl(
|
|
||||||
input: Any,
|
|
||||||
locale: Locale,
|
|
||||||
): Float {
|
|
||||||
if (input !is FloatValue) {
|
|
||||||
throw CoercingParseLiteralException(
|
|
||||||
CoercingUtil.i18nMsg(
|
|
||||||
locale,
|
|
||||||
"Scalar.unexpectedAstType",
|
|
||||||
"FloatValue",
|
|
||||||
CoercingUtil.typeName(input),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return input.value.toFloat()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun valueToLiteralImpl(input: Any): FloatValue =
|
|
||||||
FloatValue
|
|
||||||
.newFloatValue()
|
|
||||||
.value(
|
|
||||||
toDoubleImpl(input) ?: throw CoercingSerializeException(
|
|
||||||
CoercingUtil.i18nMsg(
|
|
||||||
Locale.getDefault(),
|
|
||||||
"Float.unexpectedRawValueType",
|
|
||||||
CoercingUtil.typeName(input),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
).build()
|
|
||||||
|
|
||||||
@Deprecated("")
|
|
||||||
override fun serialize(dataFetcherResult: Any): Double =
|
|
||||||
toDoubleImpl(dataFetcherResult) ?: throw CoercingSerializeException(
|
|
||||||
CoercingUtil.i18nMsg(
|
|
||||||
Locale.getDefault(),
|
|
||||||
"Float.unexpectedRawValueType",
|
|
||||||
CoercingUtil.typeName(dataFetcherResult),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
@Throws(CoercingSerializeException::class)
|
|
||||||
override fun serialize(
|
|
||||||
dataFetcherResult: Any,
|
|
||||||
graphQLContext: GraphQLContext,
|
|
||||||
locale: Locale,
|
|
||||||
): Double =
|
|
||||||
toDoubleImpl(dataFetcherResult) ?: throw CoercingSerializeException(
|
|
||||||
CoercingUtil.i18nMsg(
|
|
||||||
locale,
|
|
||||||
"Float.unexpectedRawValueType",
|
|
||||||
CoercingUtil.typeName(dataFetcherResult),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
@Deprecated("")
|
|
||||||
override fun parseValue(input: Any): Float = parseValueImpl(input, Locale.getDefault())
|
|
||||||
|
|
||||||
@Throws(CoercingParseValueException::class)
|
|
||||||
override fun parseValue(
|
|
||||||
input: Any,
|
|
||||||
graphQLContext: GraphQLContext,
|
|
||||||
locale: Locale,
|
|
||||||
): Float = parseValueImpl(input, locale)
|
|
||||||
|
|
||||||
@Deprecated("")
|
|
||||||
override fun parseLiteral(input: Any): Float = parseLiteralImpl(input, Locale.getDefault())
|
|
||||||
|
|
||||||
@Throws(CoercingParseLiteralException::class)
|
|
||||||
override fun parseLiteral(
|
|
||||||
input: Value<*>,
|
|
||||||
variables: CoercedVariables,
|
|
||||||
graphQLContext: GraphQLContext,
|
|
||||||
locale: Locale,
|
|
||||||
): Float = parseLiteralImpl(input, locale)
|
|
||||||
|
|
||||||
@Deprecated("")
|
|
||||||
override fun valueToLiteral(input: Any): Value<*> = valueToLiteralImpl(input)
|
|
||||||
|
|
||||||
override fun valueToLiteral(
|
|
||||||
input: Any,
|
|
||||||
graphQLContext: GraphQLContext,
|
|
||||||
locale: Locale,
|
|
||||||
): Value<*> = valueToLiteralImpl(input)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user