Search in sources :

Example 1 with Query

use of com.apollographql.apollo.api.Query in project apollo-android by apollographql.

the class ApolloCallTracker method registerCall.

/**
 * <p>Adds provided {@link ApolloCall} that is currently in progress.</p>
 *
 * <p><b>Note</b>: This method needs to be called right before an apolloCall is executed.</p>
 */
void registerCall(@Nonnull ApolloCall call) {
    checkNotNull(call, "call == null");
    Operation operation = call.operation();
    if (operation instanceof Query) {
        registerQueryCall((ApolloQueryCall) call);
    } else if (operation instanceof Mutation) {
        registerMutationCall((ApolloMutationCall) call);
    } else {
        throw new IllegalArgumentException("Unknown call type");
    }
}
Also used : ApolloMutationCall(com.apollographql.apollo.ApolloMutationCall) Query(com.apollographql.apollo.api.Query) Operation(com.apollographql.apollo.api.Operation) Mutation(com.apollographql.apollo.api.Mutation)

Example 2 with Query

use of com.apollographql.apollo.api.Query in project apollo-android by apollographql.

the class ResponseFetcherTest method setUp.

@Before
public void setUp() {
    okHttpClient = new OkHttpClient.Builder().build();
    emptyQuery = new Query() {

        OperationName operationName = new OperationName() {

            @Override
            public String name() {
                return "emptyQuery";
            }
        };

        @Override
        public String queryDocument() {
            return "";
        }

        @Override
        public Variables variables() {
            return EMPTY_VARIABLES;
        }

        @Override
        public ResponseFieldMapper<Data> responseFieldMapper() {
            return new ResponseFieldMapper<Data>() {

                @Override
                public Data map(ResponseReader responseReader) {
                    return null;
                }
            };
        }

        @Nonnull
        @Override
        public OperationName name() {
            return operationName;
        }

        @Nonnull
        @Override
        public String operationId() {
            return "";
        }

        @Override
        public Object wrapData(Data data) {
            return data;
        }
    };
}
Also used : ResponseFieldMapper(com.apollographql.apollo.api.ResponseFieldMapper) Query(com.apollographql.apollo.api.Query) OperationName(com.apollographql.apollo.api.OperationName) Nonnull(javax.annotation.Nonnull) ResponseReader(com.apollographql.apollo.api.ResponseReader) Before(org.junit.Before)

Example 3 with Query

use of com.apollographql.apollo.api.Query in project apollo-android by apollographql.

the class RealApolloCall method prepareInterceptorChain.

private ApolloInterceptorChain prepareInterceptorChain(Operation operation) {
    List<ApolloInterceptor> interceptors = new ArrayList<>();
    HttpCachePolicy.Policy httpCachePolicy = operation instanceof Query ? this.httpCachePolicy : null;
    ResponseFieldMapper responseFieldMapper = responseFieldMapperFactory.create(operation);
    interceptors.addAll(applicationInterceptors);
    interceptors.add(responseFetcher.provideInterceptor(logger));
    interceptors.add(new ApolloCacheInterceptor(apolloStore, responseFieldMapper, dispatcher, logger));
    interceptors.add(new ApolloParseInterceptor(httpCache, apolloStore.networkResponseNormalizer(), responseFieldMapper, scalarTypeAdapters, logger));
    interceptors.add(new ApolloServerInterceptor(serverUrl, httpCallFactory, httpCachePolicy, false, scalarTypeAdapters, logger, sendOperationdIdentifiers));
    return new RealApolloInterceptorChain(interceptors);
}
Also used : ResponseFieldMapper(com.apollographql.apollo.api.ResponseFieldMapper) RealApolloInterceptorChain(com.apollographql.apollo.internal.interceptor.RealApolloInterceptorChain) Query(com.apollographql.apollo.api.Query) ApolloParseInterceptor(com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor) ArrayList(java.util.ArrayList) HttpCachePolicy(com.apollographql.apollo.api.cache.http.HttpCachePolicy) ApolloServerInterceptor(com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor) ApolloInterceptor(com.apollographql.apollo.interceptor.ApolloInterceptor) ApolloCacheInterceptor(com.apollographql.apollo.internal.interceptor.ApolloCacheInterceptor)

Example 4 with Query

use of com.apollographql.apollo.api.Query in project apollo-android by apollographql.

the class ApolloCallTracker method unregisterCall.

/**
 * <p>Removes provided {@link ApolloCall} that finished his execution, if it is found, else throws an
 * {@link AssertionError}.</p>
 *
 * If the removal operation is successful and no active running calls are found, then the registered
 * {@link ApolloCallTracker#idleResourceCallback} is invoked.
 *
 * <p><b>Note</b>: This method needs to be called right after an apolloCall is completed (whether successful or
 * failed).</p>
 */
void unregisterCall(@Nonnull ApolloCall call) {
    checkNotNull(call, "call == null");
    Operation operation = call.operation();
    if (operation instanceof Query) {
        unregisterQueryCall((ApolloQueryCall) call);
    } else if (operation instanceof Mutation) {
        unregisterMutationCall((ApolloMutationCall) call);
    } else {
        throw new IllegalArgumentException("Unknown call type");
    }
}
Also used : ApolloMutationCall(com.apollographql.apollo.ApolloMutationCall) Query(com.apollographql.apollo.api.Query) Operation(com.apollographql.apollo.api.Operation) Mutation(com.apollographql.apollo.api.Mutation)

Example 5 with Query

use of com.apollographql.apollo.api.Query in project apollo-android by apollographql.

the class ApolloExceptionTest method setUp.

@Before
public void setUp() {
    apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(new OkHttpClient.Builder().connectTimeout(TIMEOUT_SECONDS, TimeUnit.SECONDS).readTimeout(TIMEOUT_SECONDS, TimeUnit.SECONDS).build()).build();
    emptyQuery = new Query() {

        OperationName operationName = new OperationName() {

            @Override
            public String name() {
                return "emptyQuery";
            }
        };

        @Override
        public String queryDocument() {
            return "";
        }

        @Override
        public Variables variables() {
            return EMPTY_VARIABLES;
        }

        @Override
        public ResponseFieldMapper<Data> responseFieldMapper() {
            return new ResponseFieldMapper<Data>() {

                @Override
                public Data map(ResponseReader responseReader) {
                    return null;
                }
            };
        }

        @Nonnull
        @Override
        public OperationName name() {
            return operationName;
        }

        @Nonnull
        @Override
        public String operationId() {
            return "";
        }

        @Override
        public Object wrapData(Data data) {
            return data;
        }
    };
}
Also used : ResponseFieldMapper(com.apollographql.apollo.api.ResponseFieldMapper) Query(com.apollographql.apollo.api.Query) OperationName(com.apollographql.apollo.api.OperationName) Nonnull(javax.annotation.Nonnull) ResponseReader(com.apollographql.apollo.api.ResponseReader) Before(org.junit.Before)

Aggregations

Query (com.apollographql.apollo.api.Query)5 ResponseFieldMapper (com.apollographql.apollo.api.ResponseFieldMapper)3 ApolloMutationCall (com.apollographql.apollo.ApolloMutationCall)2 Mutation (com.apollographql.apollo.api.Mutation)2 Operation (com.apollographql.apollo.api.Operation)2 OperationName (com.apollographql.apollo.api.OperationName)2 ResponseReader (com.apollographql.apollo.api.ResponseReader)2 Nonnull (javax.annotation.Nonnull)2 Before (org.junit.Before)2 HttpCachePolicy (com.apollographql.apollo.api.cache.http.HttpCachePolicy)1 ApolloInterceptor (com.apollographql.apollo.interceptor.ApolloInterceptor)1 ApolloCacheInterceptor (com.apollographql.apollo.internal.interceptor.ApolloCacheInterceptor)1 ApolloParseInterceptor (com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor)1 ApolloServerInterceptor (com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor)1 RealApolloInterceptorChain (com.apollographql.apollo.internal.interceptor.RealApolloInterceptorChain)1 ArrayList (java.util.ArrayList)1