Tabnine Logo
Operation
Code IndexAdd Tabnine to your IDE (free)

How to use
Operation
in
com.apollographql.apollo.api

Best Java code snippets using com.apollographql.apollo.api.Operation (Showing top 20 results out of 315)

origin: apollographql/apollo-android

 static ByteString httpRequestBody(Operation operation, ScalarTypeAdapters scalarTypeAdapters,
   boolean writeQueryDocument) throws IOException {
  Buffer buffer = new Buffer();
  JsonWriter jsonWriter = JsonWriter.of(buffer);
  jsonWriter.setSerializeNulls(true);
  jsonWriter.beginObject();
  jsonWriter.name("operationName").value(operation.name().name());
  jsonWriter.name("variables").beginObject();
  operation.variables().marshaller().marshal(new InputFieldJsonWriter(jsonWriter, scalarTypeAdapters));
  jsonWriter.endObject();
  jsonWriter.name("extensions")
    .beginObject()
    .name("persistedQuery")
    .beginObject()
    .name("version").value(1)
    .name("sha256Hash").value(operation.operationId())
    .endObject()
    .endObject();
  if (writeQueryDocument) {
   jsonWriter.name("query").value(operation.queryDocument().replaceAll("\\n", ""));
  }
  jsonWriter.endObject();
  jsonWriter.close();
  return buffer.readByteString();
 }
}
origin: apollographql/apollo-android

 @Nullable @Override public T execute(ReadableStore cache) {
  Record rootRecord = cache.read(CacheKeyResolver.rootKeyForOperation(operation).key(), CacheHeaders.NONE);
  if (rootRecord == null) {
   return null;
  }
  ResponseFieldMapper<D> responseFieldMapper = operation.responseFieldMapper();
  CacheFieldValueResolver fieldValueResolver = new CacheFieldValueResolver(cache, operation.variables(),
    cacheKeyResolver(), CacheHeaders.NONE, cacheKeyBuilder);
  //noinspection unchecked
  RealResponseReader<Record> responseReader = new RealResponseReader<>(operation.variables(), rootRecord,
    fieldValueResolver, scalarTypeAdapters, ResponseNormalizer.NO_OP_NORMALIZER);
  return operation.wrapData(responseFieldMapper.map(responseReader));
 }
});
origin: apollographql/apollo-android

Call httpCall(Operation operation, CacheHeaders cacheHeaders, boolean writeQueryDocument) throws IOException {
 RequestBody requestBody = RequestBody.create(MEDIA_TYPE, httpRequestBody(operation, scalarTypeAdapters,
   writeQueryDocument));
 Request.Builder requestBuilder = new Request.Builder()
   .url(serverUrl)
   .post(requestBody)
   .header(HEADER_ACCEPT_TYPE, ACCEPT_TYPE)
   .header(HEADER_CONTENT_TYPE, CONTENT_TYPE)
   .header(HEADER_APOLLO_OPERATION_ID, operation.operationId())
   .header(HEADER_APOLLO_OPERATION_NAME, operation.name().name())
   .tag(operation.operationId());
 if (cachePolicy.isPresent()) {
  HttpCachePolicy.Policy cachePolicy = this.cachePolicy.get();
  boolean skipCacheHttpResponse = "true".equalsIgnoreCase(cacheHeaders.headerValue(
    ApolloCacheHeaders.DO_NOT_STORE));
  String cacheKey = httpRequestBody(operation, scalarTypeAdapters, true).md5().hex();
  requestBuilder = requestBuilder
    .header(HttpCache.CACHE_KEY_HEADER, cacheKey)
    .header(HttpCache.CACHE_FETCH_STRATEGY_HEADER, cachePolicy.fetchStrategy.name())
    .header(HttpCache.CACHE_EXPIRE_TIMEOUT_HEADER, String.valueOf(cachePolicy.expireTimeoutMs()))
    .header(HttpCache.CACHE_EXPIRE_AFTER_READ_HEADER, Boolean.toString(cachePolicy.expireAfterRead))
    .header(HttpCache.CACHE_PREFETCH_HEADER, Boolean.toString(prefetch))
    .header(HttpCache.CACHE_DO_NOT_STORE, Boolean.toString(skipCacheHttpResponse));
 }
 return httpCallFactory.newCall(requestBuilder.build());
}
origin: apollographql/apollo-android

@SuppressWarnings("unchecked")
public Response<W> parse(@NotNull Map<String, Object> payload) {
 checkNotNull(payload, "payload == null");
 D data = null;
 if (payload.containsKey("data")) {
  Map<String, Object> buffer = (Map<String, Object>) payload.get("data");
  RealResponseReader<Map<String, Object>> realResponseReader = new RealResponseReader<>(operation.variables(),
    buffer, new MapFieldValueResolver(), scalarTypeAdapters, responseNormalizer);
  data = (D) responseFieldMapper.map(realResponseReader);
 }
 List<Error> errors = null;
 if (payload.containsKey("errors")) {
  List<Map<String, Object>> errorPayloads = (List<Map<String, Object>>) payload.get("errors");
  if (errorPayloads != null) {
   errors = new ArrayList<>();
   for (Map<String, Object> errorPayload : errorPayloads) {
    errors.add(readError(errorPayload));
   }
  }
 }
 return Response.<W>builder(operation)
   .data(operation.wrapData(data))
   .errors(errors)
   .dependentKeys(responseNormalizer.dependentKeys())
   .build();
}
origin: apollographql/apollo-android

/**
 * <p>Adds provided {@link ApolloMutationCall} that is currently in progress.</p>
 *
 * <p><b>Note</b>: This method needs to be called right before an apolloCall is executed.</p>
 */
void registerMutationCall(@NotNull ApolloMutationCall apolloMutationCall) {
 checkNotNull(apolloMutationCall, "apolloMutationCall == null");
 OperationName operationName = apolloMutationCall.operation().name();
 registerCall(activeMutationCalls, operationName, apolloMutationCall);
}
origin: com.amazonaws/aws-android-sdk-appsync-runtime

private RequestBody httpRequestBody(Operation operation) throws IOException {
 Buffer buffer = new Buffer();
 JsonWriter jsonWriter = JsonWriter.of(buffer);
 jsonWriter.beginObject();
 if (sendOperationIdentifiers) {
  jsonWriter.name("id").value(operation.operationId());
 } else {
  jsonWriter.name("query").value(operation.queryDocument().replaceAll("\\n", ""));
 }
 jsonWriter.name("variables").beginObject();
 operation.variables().marshaller().marshal(new InputFieldJsonWriter(jsonWriter, scalarTypeAdapters));
 jsonWriter.endObject();
 jsonWriter.endObject();
 jsonWriter.close();
 return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
origin: apollographql/apollo-android

return new RealResponseReader<>(EMPTY_OPERATION.variables(), recordSet, new MapFieldValueResolver(),
  new ScalarTypeAdapters(customTypeAdapters), NO_OP_NORMALIZER);
origin: awslabs/aws-mobile-appsync-sdk-android

private String httpRequestBody(Operation operation) throws IOException {
  Buffer buffer = new Buffer();
  JsonWriter jsonWriter = JsonWriter.of(buffer);
  jsonWriter.beginObject();
  jsonWriter.name("query").value(operation.queryDocument().replaceAll("\\n", ""));
  jsonWriter.name("variables").beginObject();
  operation.variables().marshaller().marshal(new InputFieldJsonWriter(jsonWriter, scalarTypeAdapters));
  jsonWriter.endObject();
  jsonWriter.endObject();
  jsonWriter.close();
  return buffer.readUtf8();
}
origin: awslabs/aws-mobile-appsync-sdk-android

@Override
public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain, @Nonnull Executor dispatcher, @Nonnull CallBack callBack) {
  if(mutationMap.containsKey(request.operation.operationId())) {
    // already in map
  }
}
origin: apollographql/apollo-android

 @NotNull public ResponseFieldMapper create(@NotNull 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);
 }
}
origin: apollographql/apollo-android

.data(operation.wrapData(data))
.errors(errors)
.dependentKeys(responseNormalizer.dependentKeys())
origin: apollographql/apollo-android

/**
 * <p>Adds provided {@link ApolloPrefetch} that is currently in progress.</p>
 *
 * <p><b>Note</b>: This method needs to be called right before a prefetch call is executed.</p>
 */
void registerPrefetchCall(@NotNull ApolloPrefetch apolloPrefetch) {
 checkNotNull(apolloPrefetch, "apolloPrefetch == null");
 OperationName operationName = apolloPrefetch.operation().name();
 registerCall(activePrefetchCalls, operationName, apolloPrefetch);
}
origin: apollographql/apollo-android

 @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();
  }
 }
});
origin: awslabs/aws-mobile-appsync-sdk-android

private RequestBody httpRequestBody(Operation operation) throws IOException {
 Buffer buffer = new Buffer();
 JsonWriter jsonWriter = JsonWriter.of(buffer);
 jsonWriter.beginObject();
 if (sendOperationIdentifiers) {
  jsonWriter.name("id").value(operation.operationId());
 } else {
  jsonWriter.name("query").value(operation.queryDocument().replaceAll("\\n", ""));
 }
 jsonWriter.name("variables").beginObject();
 operation.variables().marshaller().marshal(new InputFieldJsonWriter(jsonWriter, scalarTypeAdapters));
 jsonWriter.endObject();
 jsonWriter.endObject();
 jsonWriter.close();
 return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
origin: apollographql/apollo-android

 @Override public Set<String> execute(WriteableStore cache) {
  RealResponseWriter responseWriter = new RealResponseWriter(operation.variables(), scalarTypeAdapters);
  operationData.marshaller().marshal(responseWriter);
  ResponseNormalizer<Map<String, Object>> responseNormalizer = networkResponseNormalizer();
  responseNormalizer.willResolveRootQuery(operation);
  responseWriter.resolveFields(responseNormalizer);
  if (optimistic) {
   List<Record> updatedRecords = new ArrayList<>();
   for (Record record : responseNormalizer.records()) {
    updatedRecords.add(record.toBuilder().mutationId(mutationId).build());
   }
   return optimisticCache.mergeOptimisticUpdates(updatedRecords);
  } else {
   return optimisticCache.merge(responseNormalizer.records(), CacheHeaders.NONE);
  }
 }
});
origin: apollographql/apollo-android

 @NotNull @Override public Optional<InterceptorRequest> apply(@NotNull Response response) {
  if (response.hasErrors()) {
   if (isPersistedQueryNotFound(response.errors())) {
    logger.w("GraphQL server couldn't find Automatic Persisted Query for operation name: "
      + request.operation.name().name() + " id: " + request.operation.operationId());
    return Optional.of(request.toBuilder().sendQueryDocument(true).build());
   }
   if (isPersistedQueryNotSupported(response.errors())) {
    // TODO how to disable Automatic Persisted Queries in future and how to notify user about this
    logger.e("GraphQL server doesn't support Automatic Persisted Queries");
    return Optional.of(request.toBuilder().sendQueryDocument(true).build());
   }
  }
  return Optional.absent();
 }
});
origin: com.amazonaws/aws-android-sdk-appsync-runtime

private Call httpCall(Operation operation) throws IOException {
 RequestBody requestBody = httpRequestBody(operation);
 Request.Builder requestBuilder = new Request.Builder()
   .url(serverUrl)
   .post(requestBody)
   .header(HEADER_ACCEPT_TYPE, ACCEPT_TYPE)
   .header(HEADER_CONTENT_TYPE, CONTENT_TYPE)
   .header(HEADER_APOLLO_OPERATION_ID, operation.operationId());
 if (cachePolicy.isPresent()) {
  HttpCachePolicy.Policy cachePolicy = this.cachePolicy.get();
  String cacheKey = cacheKey(requestBody);
  requestBuilder = requestBuilder
    .header(HttpCache.CACHE_KEY_HEADER, cacheKey)
    .header(HttpCache.CACHE_FETCH_STRATEGY_HEADER, cachePolicy.fetchStrategy.name())
    .header(HttpCache.CACHE_EXPIRE_TIMEOUT_HEADER, String.valueOf(cachePolicy.expireTimeoutMs()))
    .header(HttpCache.CACHE_EXPIRE_AFTER_READ_HEADER, Boolean.toString(cachePolicy.expireAfterRead))
    .header(HttpCache.CACHE_PREFETCH_HEADER, Boolean.toString(prefetch));
 }
 return httpCallFactory.newCall(requestBuilder.build());
}
origin: com.amazonaws/aws-android-sdk-appsync-runtime

 @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);
 }
}
origin: com.amazonaws/aws-android-sdk-appsync-runtime

.data(operation.wrapData(data))
.errors(errors)
.dependentKeys(responseNormalizer.dependentKeys())
origin: apollographql/apollo-android

/**
 * <p>Adds provided {@link ApolloQueryWatcher} that is currently in progress.</p>
 *
 * <p><b>Note</b>: This method needs to be called right before
 * {@link ApolloQueryWatcher#enqueueAndWatch(ApolloCall.Callback)}.</p>
 */
void registerQueryWatcher(@NotNull ApolloQueryWatcher queryWatcher) {
 checkNotNull(queryWatcher, "queryWatcher == null");
 OperationName operationName = queryWatcher.operation().name();
 registerCall(activeQueryWatchers, operationName, queryWatcher);
}
com.apollographql.apollo.apiOperation

Javadoc

Represents a GraphQL operation (mutation or query).

Most used methods

  • variables
    Returns the variables associated with this GraphQL operation.
  • operationId
    Returns a unique identifier for this operation.
  • queryDocument
    Returns the raw GraphQL operation String.
  • name
    Returns GraphQL operation name.
  • responseFieldMapper
    Returns a mapper that maps the server response data to generated model class D.
  • wrapData
    Wraps the generated response data class D with another class. For example, a use case for this would

Popular in Java

  • Start an intent from android
  • getExternalFilesDir (Context)
  • getSystemService (Context)
  • startActivity (Activity)
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • BoxLayout (javax.swing)
  • JFrame (javax.swing)
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Join (org.hibernate.mapping)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now