mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 06:42:05 +01:00
Preparation for GraphQL
This commit is contained in:
@@ -61,6 +61,8 @@ kotlin {
|
||||
api(libs.ktor.websockets)
|
||||
api(libs.okio)
|
||||
api(libs.dateTime)
|
||||
api(libs.apollo.runtime)
|
||||
api(libs.apollo.engine.ktor)
|
||||
api(projects.core)
|
||||
api(projects.i18n)
|
||||
api(projects.domain)
|
||||
@@ -124,5 +126,7 @@ android {
|
||||
apollo {
|
||||
service("service") {
|
||||
packageName.set("ca.gosyer.jui.data.graphql")
|
||||
generateMethods.set(listOf("equalsHashCode"))
|
||||
mapScalar("LongString","kotlin.Long", "ca.gosyer.jui.data.scalars.LongStringScalar")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import ca.gosyer.jui.domain.server.service.ServerPreferences
|
||||
import ca.gosyer.jui.domain.settings.service.SettingsRepository
|
||||
import ca.gosyer.jui.domain.source.service.SourceRepository
|
||||
import ca.gosyer.jui.domain.updates.service.UpdatesRepository
|
||||
import com.apollographql.apollo3.ApolloClient
|
||||
import com.apollographql.apollo3.network.ktorClient
|
||||
import de.jensklingenberg.ktorfit.Ktorfit
|
||||
import me.tatarka.inject.annotations.Provides
|
||||
|
||||
@@ -35,6 +37,15 @@ interface DataComponent {
|
||||
.baseUrl(serverPreferences.serverUrl().get().toString().addSuffix('/'))
|
||||
.build()
|
||||
|
||||
@Provides
|
||||
fun apolloClient(
|
||||
http: Http,
|
||||
serverPreferences: ServerPreferences,
|
||||
) = ApolloClient.Builder()
|
||||
.serverUrl(serverPreferences.serverUrl().get().toString())
|
||||
.ktorClient(http)
|
||||
.build()
|
||||
|
||||
@Provides
|
||||
fun backupRepository(ktorfit: Ktorfit) = ktorfit.create<BackupRepository>()
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.jui.data.scalars
|
||||
|
||||
import com.apollographql.apollo3.api.Adapter
|
||||
import com.apollographql.apollo3.api.CustomScalarAdapters
|
||||
import com.apollographql.apollo3.api.json.JsonReader
|
||||
import com.apollographql.apollo3.api.json.JsonWriter
|
||||
|
||||
object LongStringScalar : Adapter<Long> {
|
||||
override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): Long {
|
||||
return reader.nextString()!!.toLong()
|
||||
}
|
||||
|
||||
override fun toJson(
|
||||
writer: JsonWriter,
|
||||
customScalarAdapters: CustomScalarAdapters,
|
||||
value: Long,
|
||||
) {
|
||||
writer.value(value.toString())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user