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;
}
};
}
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);
}
}
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);
}
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);
}
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;
}
};
}
Aggregations