Search in sources :

Example 1 with ResponseFieldMapper

use of com.apollographql.apollo.api.ResponseFieldMapper 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 2 with ResponseFieldMapper

use of com.apollographql.apollo.api.ResponseFieldMapper 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);
    }
}
Also used : ResponseFieldMapper(com.apollographql.apollo.api.ResponseFieldMapper) Response(com.apollographql.apollo.api.Response) OperationResponseParser(com.apollographql.apollo.response.OperationResponseParser) ApolloNetworkException(com.apollographql.apollo.exception.ApolloNetworkException)

Example 3 with ResponseFieldMapper

use of com.apollographql.apollo.api.ResponseFieldMapper 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 ResponseFieldMapper

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

the class ResponseFieldMapperFactory method create.

@Nonnull
public ResponseFieldMapper create(@Nonnull Operation operation) {
    checkNotNull(operation, "operation == null");
    Class operationClass = operation.getClass();
    ResponseFieldMapper mapper = pool.get(operationClass);
    if (mapper != null) {
        return mapper;
    }
    pool.putIfAbsent(operationClass, operation.responseFieldMapper());
    return pool.get(operationClass);
}
Also used : ResponseFieldMapper(com.apollographql.apollo.api.ResponseFieldMapper) Nonnull(javax.annotation.Nonnull)

Example 5 with ResponseFieldMapper

use of com.apollographql.apollo.api.ResponseFieldMapper 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

ResponseFieldMapper (com.apollographql.apollo.api.ResponseFieldMapper)5 Query (com.apollographql.apollo.api.Query)3 Nonnull (javax.annotation.Nonnull)3 OperationName (com.apollographql.apollo.api.OperationName)2 ResponseReader (com.apollographql.apollo.api.ResponseReader)2 Before (org.junit.Before)2 Response (com.apollographql.apollo.api.Response)1 HttpCachePolicy (com.apollographql.apollo.api.cache.http.HttpCachePolicy)1 ApolloNetworkException (com.apollographql.apollo.exception.ApolloNetworkException)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 OperationResponseParser (com.apollographql.apollo.response.OperationResponseParser)1 ArrayList (java.util.ArrayList)1