diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt index a260511f..9965fabd 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt @@ -20,8 +20,8 @@ import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.transactions.transaction import suwayomi.tachidesk.graphql.directives.RequireAuth 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.FloatFilter import suwayomi.tachidesk.graphql.queries.filter.HasGetOp import suwayomi.tachidesk.graphql.queries.filter.IntFilter import suwayomi.tachidesk.graphql.queries.filter.LongFilter @@ -158,7 +158,7 @@ class ChapterQuery { val url: StringFilter? = null, val name: StringFilter? = null, val uploadDate: LongFilter? = null, - val chapterNumber: FloatFilter? = null, + val chapterNumber: DoubleFilter? = null, val scanlator: StringFilter? = null, val mangaId: IntFilter? = null, val isRead: BooleanFilter? = null, @@ -181,7 +181,7 @@ class ChapterQuery { andFilterWithCompareString(ChapterTable.url, url), andFilterWithCompareString(ChapterTable.name, name), andFilterWithCompare(ChapterTable.date_upload, uploadDate), - andFilterWithCompare(ChapterTable.chapter_number, chapterNumber), + andFilterWithCompare(ChapterTable.chapter_number, chapterNumber?.toFloatFilter()), andFilterWithCompareString(ChapterTable.scanlator, scanlator), andFilterWithCompareEntity(ChapterTable.manga, mangaId), andFilterWithCompare(ChapterTable.isRead, isRead), diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/filter/Filter.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/filter/Filter.kt index 19a4c077..a06cf445 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/filter/Filter.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/filter/Filter.kt @@ -304,7 +304,26 @@ data class DoubleFilter( override val lessThanOrEqualTo: Double? = null, override val greaterThan: Double? = null, override val greaterThanOrEqualTo: Double? = null, -) : ComparableScalarFilter +) : ComparableScalarFilter { + 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( override val isNull: Boolean? = null, diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt index 35e3a5a1..c3dedfd9 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt @@ -46,7 +46,6 @@ import suwayomi.tachidesk.graphql.queries.UpdateQuery import suwayomi.tachidesk.graphql.server.primitives.Cursor import suwayomi.tachidesk.graphql.server.primitives.GraphQLCursor 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.GraphQLUpload import suwayomi.tachidesk.graphql.subscriptions.DownloadSubscription @@ -65,7 +64,6 @@ class CustomSchemaGeneratorHooks : FlowSubscriptionSchemaGeneratorHooks() { override fun willGenerateGraphQLType(type: KType): GraphQLType? = when (type.classifier as? KClass<*>) { Long::class -> GraphQLLongAsString // encode to string for JS - Float::class -> GraphQLFloatAsDouble // encode float as double Duration::class -> GraphQLDurationAsString // encode Duration as ISO-8601 string Cursor::class -> GraphQLCursor UploadedFile::class -> GraphQLUpload diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/primitives/FloatAsDouble.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/primitives/FloatAsDouble.kt deleted file mode 100644 index 02474fe7..00000000 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/primitives/FloatAsDouble.kt +++ /dev/null @@ -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 { - 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) -}