-
Notifications
You must be signed in to change notification settings - Fork 29
feat(feed): implement real-time GraphQL feed with subscriptions #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| query GetFeedMessages { | ||
| feedItemsConnection(first: 1000) { | ||
| nodes { | ||
| ...FeedMessageDetails | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fragment FeedMessageDetails on FeedItem { | ||
| id | ||
| type | ||
| title | ||
| body | ||
| createdAt | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package fr.androidmakers.store.graphql | ||
|
|
||
| import com.apollographql.apollo.ApolloClient | ||
| import fr.androidmakers.domain.model.FeedItem | ||
| import fr.androidmakers.domain.repo.FeedRepository | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.catch | ||
| import kotlinx.coroutines.flow.mapNotNull | ||
| import kotlinx.coroutines.flow.map | ||
| import kotlinx.coroutines.flow.merge | ||
| import kotlinx.coroutines.flow.scan | ||
|
|
||
| class FeedGraphQLRepository( | ||
| private val apolloClient: ApolloClient, | ||
| ) : FeedRepository { | ||
|
|
||
| override fun getFeedItems(): Flow<Result<List<FeedItem>>> { | ||
| return apolloClient.query(GetFeedMessagesQuery()) | ||
| .cacheAndNetwork() | ||
| .map { result -> result.map { data -> data.feedItemsConnection.nodes.map { it.feedMessageDetails.toFeedItem() } } } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package fr.androidmakers.store.graphql | ||
|
|
||
| import fr.androidmakers.domain.model.FeedItem | ||
| import fr.androidmakers.domain.model.MessageType | ||
| import fr.androidmakers.store.graphql.fragment.FeedMessageDetails | ||
| import fr.androidmakers.store.graphql.type.FeedItemType | ||
|
|
||
| fun FeedMessageDetails.toFeedItem(): FeedItem { | ||
| return when (type) { | ||
| FeedItemType.ALERT -> FeedItem.Alert( | ||
| id = id, | ||
| title = title, | ||
| message = body, | ||
| ) | ||
| else -> FeedItem.Message( | ||
| id = id, | ||
| type = when (type) { | ||
| FeedItemType.ANNOUNCEMENT -> MessageType.ANNOUNCEMENT | ||
| else -> MessageType.INFO | ||
| }, | ||
| title = title, | ||
| body = body, | ||
| createdAt = createdAt, | ||
| ) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package fr.androidmakers.store.graphql | ||
|
|
||
| import com.apollographql.apollo.api.Adapter | ||
| import com.apollographql.apollo.api.CustomScalarAdapters | ||
| import com.apollographql.apollo.api.json.JsonReader | ||
| import com.apollographql.apollo.api.json.JsonWriter | ||
| import kotlinx.datetime.Instant | ||
|
|
||
| val KotlinxInstantAdapter = object : Adapter<Instant> { | ||
| override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): Instant { | ||
| val str = reader.nextString() ?: throw IllegalStateException("Expected non-null Instant string") | ||
Check warningCode scanning / detekt Use check() or error() instead of throwing an IllegalStateException. Warning
Use check() or error() instead of throwing an IllegalStateException.
|
||
| return Instant.parse(str) | ||
| } | ||
|
|
||
| override fun toJson(writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, value: Instant) { | ||
| writer.value(value.toString()) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -83,8 +83,7 @@ | |||||
| <string name="remove_from_my_agenda">Remove from My Agenda</string> | ||||||
|
|
||||||
| <string name="feed">Feed</string> | ||||||
| <string name="feed_read_more">Read More</string> | ||||||
| <string name="feed_category_venue">VENUE</string> | ||||||
| <string name="feed_category_venue">VENUE</string> | ||||||
|
||||||
| <string name="feed_category_venue">VENUE</string> | |
| <string name="feed_category_venue">VENUE</string> |
Check warning
Code scanning / detekt
Line detected, which is longer than the defined maximum line length in the code style. Warning