Comments (4)
Any progress almost a year later? The approach suggested by @norio-agoop is a starting point but it's an approach that doesn't scale that well with an increase in the number of queries — just too much onFailure()
and onResponse()
boilerplate.
Right now, I have a REST API for my Android app, and using Retrofit to make the HTTP calls. Now, Retrofit has a simple class, RxJava2CallAdapterFactory.java
(~100 SLOC) which has a single dependency, CallAdapter.java
(~50 SLOC). Those classes are responsible for converting the HTTP calls to observables. Without RxJava2CallAdapterFactory
, the code looks like this (for brevity):
query.enqueue(new Callback<List<GitHubRepo>>() {
@Override
public void onResponse(Call<List<GitHubRepo>> call, Response<List<GitHubRepo>> response) {}
@Override
public void onFailure(Call<List<GitHubRepo>> call, Throwable t) { }
});
But with RxJava2CallAdapterFactory
included, it becomes:
query()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(success -> {}, failure -> {})
And that's a massive improvement! Is there something similar in the works for your SDK?
from aws-mobile-appsync-sdk-android.
@leijdekkers
We currently do not have support for Rx Java within AppSync.
I am adding @undefobj to this thread to comment on whether this would be a future roadmap item.
from aws-mobile-appsync-sdk-android.
Hope you will implement it soon. The reason is that in many Android apps, the AppSync part goes into the "Repository" part (i.e. Model in MVVM architecture) of the app where many developers use RxJava to communicate between the Repository component and the ViewModel. It is really bad practice to use the AppSync SDK in fragments/activities (i.e. the View part of the MVVM model).
Please have a look at Apollo where they already support RxJava. It should not be too hard to fully support it in AppSync SDK.
from aws-mobile-appsync-sdk-android.
@leijdekkers I'm using Rx with AppSync. Please take a look my sample code below.
/**
* getUser
*/
override fun getUser(userId: String): Single<GetUserQuery.GetUser> {
Timber.d("GetUserQuery Request: %s", userId)
return Single.create { emitter ->
appSyncClient.query(GetUserQuery.builder().user_id(userId).build())
.responseFetcher(AppSyncResponseFetchers.NETWORK_ONLY)
.enqueue(getUserCallback(emitter))
}
}
private fun getUserCallback(emitter: SingleEmitter<GetUserQuery.GetUser>): GraphQLCall.Callback<GetUserQuery.Data> {
return object : GraphQLCall.Callback<GetUserQuery.Data>() {
override fun onFailure(e: ApolloException) {
Timber.e(e)
emitter.onError(e)
}
override fun onResponse(response: Response<GetUserQuery.Data>) {
val result = response.data()?.user ?: run {
val e = Throwable("GetUserQuery Response is null")
Timber.e(e)
emitter.onError(e)
return
}
Timber.d("GetUserQuery Response: %s", result)
emitter.onSuccess(result)
}
}
}
from aws-mobile-appsync-sdk-android.
Related Issues (20)
- Execution failed for task ':app:nodeSetup'. HOT 1
- android.net.ConnectivityManager$TooManyRequestsException HOT 9
- Execution failed for task ':app:nodeSetup'. HOT 5
- Android Studio Bumblebee will further break compatibility with Jetpack libraries HOT 3
- NullPointerException: Attempt to invoke virtual method 'org.json.JSONObject com.amazonaws.mobile.config.AWSConfiguration.optJsonObject(java.lang.String)' on a null object reference HOT 3
- No ability to serlialize null input fields
- App Sync SDK crashing with SQLiteBlobTooBigException HOT 4
- How can we encrypt cache data
- AppSync codegen models throws @Nullable @Nullable HOT 4
- AppSync codegen model "S3ObjectInput" methods override error
- Cognito API InitiateAuth + REFRESH_TOKEN_AUTH does not return updated RefreshToken HOT 2
- Fatal Exception: java.lang.NullPointerException: Parameter specified as non-null is null
- AppSync gradle plugin has conflict with Apollo3 plugin HOT 1
- GraphQL subscription error 403 HOT 1
- Wrong serialisation for Enum type in WebSocketConnectionManager
- AWSAppSyncClient is not generating code from the graphql file in Android HOT 20
- AWS appsync doesn't build with agp version 8.0 HOT 5
- app crashes when retrying all subscriptions HOT 1
- Gradle configuration cache support HOT 2
- Fix critical vulnerability CVE-2022-4725 flagged by Sonarqube on dependency: aws-android-sdk-mobile-client 2.22.1 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-mobile-appsync-sdk-android.