@SuppressWarnings("unchecked") InterceptorResponse parse(Operation operation, okhttp3.Response httpResponse) throws ApolloHttpException, ApolloParseException { String cacheKey = httpResponse.request().header(HttpCache.CACHE_KEY_HEADER); if (httpResponse.isSuccessful()) { try { OperationResponseParser parser = new OperationResponseParser(operation, responseFieldMapper, scalarTypeAdapters, normalizer); Response parsedResponse = parser.parse(httpResponse.body().source()) .toBuilder() .fromCache(httpResponse.cacheResponse() != null) .build(); if (parsedResponse.hasErrors() && httpCache != null) { httpCache.removeQuietly(cacheKey); } return new InterceptorResponse(httpResponse, parsedResponse, normalizer.records()); } catch (Exception rethrown) { logger.e(rethrown, "Failed to parse network response for operation: %s", operation); closeQuietly(httpResponse); if (httpCache != null) { httpCache.removeQuietly(cacheKey); } throw new ApolloParseException("Failed to parse http response", rethrown); } } else { logger.e("Failed to parse network response: %s", httpResponse); throw new ApolloHttpException(httpResponse); } }
@NotNull @Override public Response<T> execute(ReadableStore cache) { Record rootRecord = cache.read(CacheKeyResolver.rootKeyForOperation(operation).key(), cacheHeaders); if (rootRecord == null) { return Response.<T>builder(operation).fromCache(true).build(); } CacheFieldValueResolver fieldValueResolver = new CacheFieldValueResolver(cache, operation.variables(), cacheKeyResolver(), cacheHeaders, cacheKeyBuilder); RealResponseReader<Record> responseReader = new RealResponseReader<>(operation.variables(), rootRecord, fieldValueResolver, scalarTypeAdapters, responseNormalizer); try { responseNormalizer.willResolveRootQuery(operation); T data = operation.wrapData(responseFieldMapper.map(responseReader)); return Response.<T>builder(operation) .data(data) .fromCache(true) .dependentKeys(responseNormalizer.dependentKeys()) .build(); } catch (Exception e) { logger.e(e, "Failed to read cache response"); return Response.<T>builder(operation).fromCache(true).build(); } } });
Response parsedResponse = parser.parse(httpResponse.body().source()) .toBuilder() .fromCache(httpResponse.cacheResponse() != null) .build(); if (parsedResponse.hasErrors() && httpCache != null) {
Response parsedResponse = parser.parse(httpResponse.body().source()) .toBuilder() .fromCache(httpResponse.cacheResponse() != null) .build(); if (parsedResponse.hasErrors() && httpCache != null) {
@Nonnull @Override public Response<T> execute(ReadableStore cache) { Record rootRecord = cache.read(CacheKeyResolver.rootKeyForOperation(operation).key(), cacheHeaders); if (rootRecord == null) { return Response.<T>builder(operation).fromCache(true).build(); } CacheFieldValueResolver fieldValueResolver = new CacheFieldValueResolver(cache, operation.variables(), cacheKeyResolver(), cacheHeaders); RealResponseReader<Record> responseReader = new RealResponseReader<>(operation.variables(), rootRecord, fieldValueResolver, scalarTypeAdapters, responseNormalizer); try { responseNormalizer.willResolveRootQuery(operation); T data = operation.wrapData(responseFieldMapper.map(responseReader)); return Response.<T>builder(operation) .data(data) .fromCache(true) .dependentKeys(responseNormalizer.dependentKeys()) .build(); } catch (Exception e) { logger.e(e, "Failed to read cache response"); return Response.<T>builder(operation).fromCache(true).build(); } } });
@Nonnull @Override public Response<T> execute(ReadableStore cache) { Record rootRecord = cache.read(CacheKeyResolver.rootKeyForOperation(operation).key(), cacheHeaders); if (rootRecord == null) { return Response.<T>builder(operation).fromCache(true).build(); } CacheFieldValueResolver fieldValueResolver = new CacheFieldValueResolver(cache, operation.variables(), cacheKeyResolver(), cacheHeaders); RealResponseReader<Record> responseReader = new RealResponseReader<>(operation.variables(), rootRecord, fieldValueResolver, scalarTypeAdapters, responseNormalizer); try { responseNormalizer.willResolveRootQuery(operation); T data = operation.wrapData(responseFieldMapper.map(responseReader)); return Response.<T>builder(operation) .data(data) .fromCache(true) .dependentKeys(responseNormalizer.dependentKeys()) .build(); } catch (Exception e) { logger.e(e, "Failed to read cache response"); return Response.<T>builder(operation).fromCache(true).build(); } } });
private InterceptorResponse cacheMissResponse(Operation operation) { return new InterceptorResponse(null, Response.builder(operation).fromCache(true).build(), null); } }
private InterceptorResponse cacheMissResponse(Operation operation) { return new InterceptorResponse(null, Response.builder(operation).fromCache(true).build(), null); } }
public Builder<T> toBuilder() { return new Builder<T>(operation) .data(data) .errors(errors) .dependentKeys(dependentKeys) .fromCache(fromCache); }
public Builder<T> toBuilder() { return new Builder<T>(operation) .data(data) .errors(errors) .dependentKeys(dependentKeys) .fromCache(fromCache); }
InterceptorResponse cacheMissResponse(Operation operation) { return new InterceptorResponse(null, Response.builder(operation).fromCache(true).build(), null); } }
public Builder<T> toBuilder() { return new Builder<T>(operation) .data(data) .errors(errors) .dependentKeys(dependentKeys) .fromCache(fromCache); }