use of com.apollographql.apollo.api.Response in project apollo-android by apollographql.
the class GitHuntEntryDetailActivity method subscribeRepoCommentAdded.
private void subscribeRepoCommentAdded() {
ApolloSubscriptionCall<RepoCommentAddedSubscription.Data> subscriptionCall = application.apolloClient().subscribe(new RepoCommentAddedSubscription(repoFullName));
disposables.add(Rx2Apollo.from(subscriptionCall).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<Response<RepoCommentAddedSubscription.Data>>() {
@Override
public void onNext(Response<RepoCommentAddedSubscription.Data> response) {
commentsListViewAdapter.addItem(response.data().commentAdded().content());
}
@Override
public void onError(Throwable e) {
Log.e(TAG, e.getMessage(), e);
}
@Override
public void onComplete() {
Log.d(TAG, "Subscription exhausted");
}
}));
}
use of com.apollographql.apollo.api.Response in project apollo-android by apollographql.
the class RealSubscriptionManager method onOperationDataServerMessage.
@SuppressWarnings("unchecked")
private void onOperationDataServerMessage(OperationServerMessage.Data message) {
String subscriptionId = message.id != null ? message.id : "";
SubscriptionRecord subscriptionRecord;
synchronized (this) {
subscriptionRecord = subscriptions.get(subscriptionId);
}
if (subscriptionRecord != null) {
ResponseFieldMapper responseFieldMapper = responseFieldMapperFactory.create(subscriptionRecord.subscription);
OperationResponseParser parser = new OperationResponseParser(subscriptionRecord.subscription, responseFieldMapper, scalarTypeAdapters);
Response response;
try {
response = parser.parse(message.payload);
} catch (Exception e) {
subscriptionRecord = removeSubscriptionById(subscriptionId);
if (subscriptionRecord != null) {
subscriptionRecord.notifyOnError(new ApolloSubscriptionException("Failed to parse server message", e));
}
return;
}
subscriptionRecord.notifyOnResponse(response);
}
}
use of com.apollographql.apollo.api.Response in project apollo-android by apollographql.
the class ApolloCallbackTest method onHttpError.
@Test
public void onHttpError() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
final AtomicBoolean invoked = new AtomicBoolean();
final Handler callbackHandler = mockCallbackHandler(invoked);
final AtomicReference<ApolloException> exceptionRef = new AtomicReference<>();
server.enqueue(new MockResponse().setResponseCode(401).setBody("Unauthorized request!"));
apolloClient.query(EMPTY_QUERY).enqueue(ApolloCallback.wrap(new ApolloCall.Callback() {
@Override
public void onResponse(@Nonnull Response response) {
countDownLatch.countDown();
}
@Override
public void onFailure(@Nonnull ApolloException e) {
exceptionRef.set(e);
countDownLatch.countDown();
}
@Override
public void onHttpError(@Nonnull ApolloHttpException e) {
exceptionRef.set(e);
countDownLatch.countDown();
}
}, callbackHandler));
countDownLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
assertThat(invoked.get()).isTrue();
assertThat(exceptionRef.get()).isInstanceOf(ApolloHttpException.class);
}
use of com.apollographql.apollo.api.Response in project apollo-android by apollographql.
the class ApolloCallbackTest method onParseError.
@Test
public void onParseError() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
final AtomicBoolean invoked = new AtomicBoolean();
final Handler callbackHandler = mockCallbackHandler(invoked);
final AtomicReference<ApolloException> exceptionRef = new AtomicReference<>();
server.enqueue(new MockResponse().setResponseCode(200).setBody("nonsense"));
apolloClient.query(EMPTY_QUERY).enqueue(ApolloCallback.wrap(new ApolloCall.Callback() {
@Override
public void onResponse(@Nonnull Response response) {
countDownLatch.countDown();
}
@Override
public void onFailure(@Nonnull ApolloException e) {
countDownLatch.countDown();
}
@Override
public void onParseError(@Nonnull ApolloParseException e) {
exceptionRef.set(e);
countDownLatch.countDown();
}
}, callbackHandler));
countDownLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
assertThat(invoked.get()).isTrue();
assertThat(exceptionRef.get()).isInstanceOf(ApolloParseException.class);
}
use of com.apollographql.apollo.api.Response in project apollo-android by apollographql.
the class ApolloCallbackTest method onResponse.
@Test
public void onResponse() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
final AtomicBoolean invoked = new AtomicBoolean();
final Handler callbackHandler = mockCallbackHandler(invoked);
final AtomicReference<Response> responseRef = new AtomicReference<>();
server.enqueue(new MockResponse().setResponseCode(200).setBody("{" + " \"errors\": [" + " {" + " \"message\": \"Cannot query field \\\"names\\\" on type \\\"Species\\\".\"," + " \"locations\": [" + " {" + " \"line\": 3," + " \"column\": 5" + " }" + " ]" + " }" + " ]" + "}"));
apolloClient.query(EMPTY_QUERY).enqueue(ApolloCallback.wrap(new ApolloCall.Callback() {
@Override
public void onResponse(@Nonnull Response response) {
responseRef.set(response);
countDownLatch.countDown();
}
@Override
public void onFailure(@Nonnull ApolloException e) {
countDownLatch.countDown();
}
}, callbackHandler));
countDownLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
assertThat(invoked.get()).isTrue();
assertThat(responseRef.get()).isNotNull();
}
Aggregations