use of com.apollographql.apollo.integration.normalizer.CreateReviewMutation in project apollo-android by apollographql.
the class QueryRefetchTest method refetchNoPreCachedQuery.
@Test
@SuppressWarnings("CheckReturnValue")
public void refetchNoPreCachedQuery() throws Exception {
CreateReviewMutation mutation = new CreateReviewMutation(Episode.EMPIRE, ReviewInput.builder().stars(5).commentary("Awesome").favoriteColor(ColorInput.builder().build()).build());
server.enqueue(mockResponse("CreateReviewResponse.json"));
server.enqueue(mockResponse("ReviewsEmpireEpisodeResponse.json"));
RealApolloCall call = (RealApolloCall) apolloClient.mutate(mutation).refetchQueries(new ReviewsByEpisodeQuery(Episode.EMPIRE));
Rx2Apollo.from(call).test();
assertThat(server.getRequestCount()).isEqualTo(2);
assertResponse(apolloClient.query(new ReviewsByEpisodeQuery(Episode.EMPIRE)).responseFetcher(CACHE_ONLY), new Predicate<Response<ReviewsByEpisodeQuery.Data>>() {
@Override
public boolean test(Response<ReviewsByEpisodeQuery.Data> response) throws Exception {
assertThat(response.data().reviews()).hasSize(3);
assertThat(response.data().reviews().get(2).stars()).isEqualTo(5);
assertThat(response.data().reviews().get(2).commentary()).isEqualTo("Amazing");
return true;
}
});
}
use of com.apollographql.apollo.integration.normalizer.CreateReviewMutation in project apollo-android by apollographql.
the class QueryRefetchTest method refetchPreCachedQuery.
@Test
@SuppressWarnings("CheckReturnValue")
public void refetchPreCachedQuery() throws Exception {
enqueueAndAssertResponse(server, "ReviewsEmpireEpisodeResponse.json", apolloClient.query(new ReviewsByEpisodeQuery(Episode.EMPIRE)).responseFetcher(NETWORK_FIRST), new Predicate<Response<ReviewsByEpisodeQuery.Data>>() {
@Override
public boolean test(Response<ReviewsByEpisodeQuery.Data> response) throws Exception {
return !response.hasErrors();
}
});
assertResponse(apolloClient.query(new ReviewsByEpisodeQuery(Episode.EMPIRE)).responseFetcher(CACHE_ONLY), new Predicate<Response<ReviewsByEpisodeQuery.Data>>() {
@Override
public boolean test(Response<ReviewsByEpisodeQuery.Data> response) throws Exception {
assertThat(response.data().reviews()).hasSize(3);
assertThat(response.data().reviews().get(2).stars()).isEqualTo(5);
assertThat(response.data().reviews().get(2).commentary()).isEqualTo("Amazing");
return true;
}
});
CreateReviewMutation mutation = new CreateReviewMutation(Episode.EMPIRE, ReviewInput.builder().stars(5).commentary("Awesome").favoriteColor(ColorInput.builder().build()).build());
server.enqueue(mockResponse("CreateReviewResponse.json"));
server.enqueue(mockResponse("ReviewsEmpireEpisodeResponseUpdated.json"));
RealApolloCall call = (RealApolloCall) apolloClient.mutate(mutation).refetchQueries(new ReviewsByEpisodeQuery(Episode.EMPIRE));
Rx2Apollo.from(call).test();
assertThat(server.getRequestCount()).isEqualTo(3);
assertResponse(apolloClient.query(new ReviewsByEpisodeQuery(Episode.EMPIRE)).responseFetcher(CACHE_ONLY), new Predicate<Response<ReviewsByEpisodeQuery.Data>>() {
@Override
public boolean test(Response<ReviewsByEpisodeQuery.Data> response) throws Exception {
assertThat(response.data().reviews()).hasSize(4);
assertThat(response.data().reviews().get(3).stars()).isEqualTo(5);
assertThat(response.data().reviews().get(3).commentary()).isEqualTo("Awesome");
return true;
}
});
}
use of com.apollographql.apollo.integration.normalizer.CreateReviewMutation in project apollo-android by apollographql.
the class QueryRefetchTest method refetchWatchers.
@Test
@SuppressWarnings("CheckReturnValue")
public void refetchWatchers() throws Exception {
server.enqueue(mockResponse("ReviewsEmpireEpisodeResponse.json"));
server.enqueue(mockResponse("CreateReviewResponse.json"));
server.enqueue(mockResponse("ReviewsEmpireEpisodeResponseUpdated.json"));
final AtomicReference<Response<ReviewsByEpisodeQuery.Data>> empireReviewsWatchResponse = new AtomicReference<>();
ApolloQueryWatcher<ReviewsByEpisodeQuery.Data> queryWatcher = apolloClient.query(new ReviewsByEpisodeQuery(Episode.EMPIRE)).watcher().refetchResponseFetcher(NETWORK_FIRST).enqueueAndWatch(new ApolloCall.Callback<ReviewsByEpisodeQuery.Data>() {
@Override
public void onResponse(@Nonnull Response<ReviewsByEpisodeQuery.Data> response) {
empireReviewsWatchResponse.set(response);
}
@Override
public void onFailure(@Nonnull ApolloException e) {
}
});
CreateReviewMutation mutation = new CreateReviewMutation(Episode.EMPIRE, ReviewInput.builder().stars(5).commentary("Awesome").favoriteColor(ColorInput.builder().build()).build());
Rx2Apollo.from(apolloClient.mutate(mutation).refetchQueries(queryWatcher.operation().name())).test();
assertThat(server.getRequestCount()).isEqualTo(3);
Response<ReviewsByEpisodeQuery.Data> empireReviewsQueryResponse = empireReviewsWatchResponse.get();
assertThat(empireReviewsQueryResponse.data().reviews()).hasSize(4);
assertThat(empireReviewsQueryResponse.data().reviews().get(3).stars()).isEqualTo(5);
assertThat(empireReviewsQueryResponse.data().reviews().get(3).commentary()).isEqualTo("Awesome");
queryWatcher.cancel();
}
Aggregations