Search in sources :

Example 6 with HeroAndFriendsNamesQuery

use of com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesQuery in project apollo-android by apollographql.

the class SendOperationIdentifiersTest method doesNotSendOperationIdsWhenFalse.

@Test
public void doesNotSendOperationIdsWhenFalse() throws Exception {
    final HeroAndFriendsNamesQuery query = new HeroAndFriendsNamesQuery(Input.fromNullable(EMPIRE));
    ApolloClient apolloClient = ApolloClient.builder().serverUrl(server.url("/")).sendOperationIdentifiers(false).build();
    apolloClient.query(query).enqueue(null);
    String serverRequest = server.takeRequest().getBody().readUtf8();
    assertThat(serverRequest.contains("\"id\":\"")).isFalse();
    assertThat(serverRequest.contains("\"query\":")).isTrue();
}
Also used : HeroAndFriendsNamesQuery(com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesQuery) Test(org.junit.Test)

Example 7 with HeroAndFriendsNamesQuery

use of com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesQuery in project apollo-android by apollographql.

the class SendOperationIdentifiersTest method operationIdHttpRequestHeader.

@Test
public void operationIdHttpRequestHeader() throws Exception {
    final HeroAndFriendsNamesQuery heroAndFriendsNamesQuery = new HeroAndFriendsNamesQuery(Input.fromNullable(EMPIRE));
    final AtomicBoolean applicationInterceptorHeader = new AtomicBoolean();
    final AtomicBoolean networkInterceptorHeader = new AtomicBoolean();
    OkHttpClient okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(Utils.immediateExecutorService())).addInterceptor(new Interceptor() {

        @Override
        public okhttp3.Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            if (request.header("X-APOLLO-OPERATION-ID").equals(heroAndFriendsNamesQuery.operationId())) {
                applicationInterceptorHeader.set(true);
            }
            return chain.proceed(chain.request());
        }
    }).addNetworkInterceptor(new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            if (request.header("X-APOLLO-OPERATION-ID").equals(heroAndFriendsNamesQuery.operationId())) {
                networkInterceptorHeader.set(true);
            }
            return chain.proceed(chain.request());
        }
    }).build();
    ApolloClient apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).dispatcher(Utils.immediateExecutor()).build();
    enqueueAndAssertResponse(server, "HeroAndFriendsNameResponse.json", apolloClient.query(heroAndFriendsNamesQuery), new Predicate<com.apollographql.apollo.api.Response<HeroAndFriendsNamesQuery.Data>>() {

        @Override
        public boolean test(com.apollographql.apollo.api.Response<HeroAndFriendsNamesQuery.Data> response) throws Exception {
            return !response.hasErrors();
        }
    });
    assertThat(applicationInterceptorHeader.get()).isTrue();
    assertThat(networkInterceptorHeader.get()).isTrue();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) IOException(java.io.IOException) Dispatcher(okhttp3.Dispatcher) IOException(java.io.IOException) Utils.enqueueAndAssertResponse(com.apollographql.apollo.Utils.enqueueAndAssertResponse) Response(okhttp3.Response) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HeroAndFriendsNamesQuery(com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesQuery) Interceptor(okhttp3.Interceptor) Test(org.junit.Test)

Aggregations

HeroAndFriendsNamesQuery (com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesQuery)7 Test (org.junit.Test)7 Record (com.apollographql.apollo.cache.normalized.Record)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Dispatcher (okhttp3.Dispatcher)3 NonNull (android.support.annotation.NonNull)2 Utils.enqueueAndAssertResponse (com.apollographql.apollo.Utils.enqueueAndAssertResponse)2 ApolloCacheHeaders (com.apollographql.apollo.cache.ApolloCacheHeaders)2 CacheHeaders (com.apollographql.apollo.cache.CacheHeaders)2 CacheKey (com.apollographql.apollo.cache.normalized.CacheKey)2 NormalizedCache (com.apollographql.apollo.cache.normalized.NormalizedCache)2 NormalizedCacheFactory (com.apollographql.apollo.cache.normalized.NormalizedCacheFactory)2 RecordFieldJsonAdapter (com.apollographql.apollo.cache.normalized.RecordFieldJsonAdapter)2 IOException (java.io.IOException)2 Nonnull (javax.annotation.Nonnull)2 OkHttpClient (okhttp3.OkHttpClient)2 Utils.assertResponse (com.apollographql.apollo.Utils.assertResponse)1 Response (com.apollographql.apollo.api.Response)1 CacheReference (com.apollographql.apollo.cache.normalized.CacheReference)1 ApolloException (com.apollographql.apollo.exception.ApolloException)1