Skip to content

Commit

Permalink
Add graphql query for fetching library entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Drumber committed Nov 23, 2024
1 parent 706d28e commit e6a7828
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .idea/graphql-settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions app/src/main/graphql/GetLibraryEntries.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
query GetLibraryEntries(
$pageSize: Int = 20
$cursor: String
$status: [LibraryEntryStatusEnum!]
$sort: LibraryEntrySortEnum = UPDATED_AT
$sortDirection: SortDirection = DESCENDING
) {
currentProfile {
library {
all(
first: $pageSize
after: $cursor
status: $status
sort: {
on: $sort
direction: $sortDirection
}
) {
nodes {
id
status
progress
rating
media {
slug
titles {
canonical
romanized
localized
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ object Kitsu {

const val API_HOST = "kitsu.app"
const val API_URL = "https://$API_HOST/api/edge/"
const val GRAPHQL_URL = "https://$API_HOST/api/graphql"
const val OAUTH_URL = "https://$API_HOST/api/oauth/"
const val BASE_URL = "https://$API_HOST"
const val USER_URL_PREFIX = "$BASE_URL/users/"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.drumber.kitsune.data.source.graphql.library

import com.apollographql.apollo.ApolloClient
import io.github.drumber.kitsune.data.source.graphql.GetLibraryEntriesQuery
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class LibraryApolloDataSource(
private val client: ApolloClient
) {

suspend fun getLibraryEntries(): GetLibraryEntriesQuery.Data {
return withContext(Dispatchers.IO) {
client.query(GetLibraryEntriesQuery()).execute().dataAssertNoErrors
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package io.github.drumber.kitsune.di
import android.content.Context
import android.os.Parcelable
import com.algolia.search.model.filter.Filter
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.network.okHttpClient
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.MapperFeature
Expand Down Expand Up @@ -36,6 +38,7 @@ val networkModule = module {
single(named("images")) { createHttpClientBuilder(false).build() }
single { createObjectMapper() }
factory<AuthenticationInterceptor> { AuthenticationInterceptorImpl(get()) }
single { createApolloClient(get()) }
}

fun createHttpClientBuilder(addLoggingInterceptor: Boolean = true) = OkHttpClient.Builder()
Expand Down Expand Up @@ -130,3 +133,8 @@ inline fun <reified T> createService(
.build()
.create(T::class.java)
}

private fun createApolloClient(httpClient: OkHttpClient) = ApolloClient.Builder()
.serverUrl(Kitsu.GRAPHQL_URL)
.okHttpClient(httpClient)
.build()

0 comments on commit e6a7828

Please sign in to comment.