• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ApolloCall类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中com.apollographql.apollo.ApolloCall的典型用法代码示例。如果您正苦于以下问题:Java ApolloCall类的具体用法?Java ApolloCall怎么用?Java ApolloCall使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ApolloCall类属于com.apollographql.apollo包,在下文中一共展示了ApolloCall类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: fetchRepositoryDetails

点赞 3

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
private void fetchRepositoryDetails() {
    ApolloCall<EntryDetailQuery.Data> entryDetailQuery = application.apolloClient()
            .query(new EntryDetailQuery(repoFullName))
            .cacheControl(CacheControl.CACHE_FIRST);

    //Example call using Rx2Support
    disposables.add(Rx2Apollo.from(entryDetailQuery)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(new DisposableSingleObserver<Response<EntryDetailQuery.Data>>() {
                @Override
                public void onSuccess(Response<EntryDetailQuery.Data> dataResponse) {
                    setEntryData(dataResponse.data());
                }

                @Override
                public void onError(Throwable e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }));
}
 

开发者ID:pranayairan,
项目名称:HelloApolloAndroid,
代码行数:22,
代码来源:GitHuntEntryDetailActivity.java

示例2: fetchRepositoryDetails

点赞 3

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
private void fetchRepositoryDetails() {
  ApolloCall<EntryDetailQuery.Data> entryDetailQuery = application.apolloClient()
      .query(new EntryDetailQuery(repoFullName))
      .responseFetcher(ApolloResponseFetchers.CACHE_FIRST);

  //Example call using Rx2Support
  disposables.add(Rx2Apollo.from(entryDetailQuery)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeWith(new DisposableObserver<Response<EntryDetailQuery.Data>>() {
        @Override public void onNext(Response<EntryDetailQuery.Data> dataResponse) {
          setEntryData(dataResponse.data());
        }

        @Override public void onError(Throwable e) {
          Log.e(TAG, e.getMessage(), e);
        }

        @Override public void onComplete() {

        }
      }));
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:24,
代码来源:GitHuntEntryDetailActivity.java

示例3: from

点赞 3

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
/**
 * Converts an {@link ApolloQueryWatcher} to an asynchronous Observable.
 *
 * @param watcher the ApolloQueryWatcher to convert.
 * @param <T>     the value type
 * @return the converted Observable
 * @throws NullPointerException if watcher == null
 */
public static <T> Observable<Response<T>> from(@Nonnull final ApolloQueryWatcher<T> watcher) {
  checkNotNull(watcher, "watcher == null");
  return Observable.create(new ObservableOnSubscribe<Response<T>>() {
    @Override public void subscribe(final ObservableEmitter<Response<T>> emitter) throws Exception {
      cancelOnObservableDisposed(emitter, watcher);

      watcher.enqueueAndWatch(new ApolloCall.Callback<T>() {
        @Override public void onResponse(@Nonnull Response<T> response) {
          if (!emitter.isDisposed()) {
            emitter.onNext(response);
          }
        }

        @Override public void onFailure(@Nonnull ApolloException e) {
          Exceptions.throwIfFatal(e);
          if (!emitter.isDisposed()) {
            emitter.onError(e);
          }
        }
      });
    }
  });
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:32,
代码来源:Rx2Apollo.java

示例4: refetchQueries

点赞 3

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
private void refetchQueries() {
  final OnCompleteCallback completeCallback = onCompleteCallback;
  final AtomicInteger callsLeft = new AtomicInteger(calls.size());
  for (final RealApolloCall call : calls) {
    //noinspection unchecked
    call.enqueue(new ApolloCall.Callback() {
      @Override public void onResponse(@Nonnull Response response) {
        if (callsLeft.decrementAndGet() == 0 && completeCallback != null) {
          completeCallback.onFetchComplete();
        }
      }

      @Override public void onFailure(@Nonnull ApolloException e) {
        if (logger != null) {
          logger.e(e, "Failed to fetch query: %s", call.operation);
        }

        if (callsLeft.decrementAndGet() == 0 && completeCallback != null) {
          completeCallback.onFetchComplete();
        }
      }
    });
  }
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:25,
代码来源:QueryReFetcher.java

示例5: activate

点赞 3

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
private synchronized void activate(Optional<ApolloCall.Callback<T>> callback) throws ApolloCanceledException {
  switch (state.get()) {
    case IDLE:
      originalCallback.set(callback.orNull());
      tracker.registerQueryWatcher(this);
      break;
    case CANCELED:
      throw new ApolloCanceledException("Call is cancelled.");
    case TERMINATED:
    case ACTIVE:
      throw new IllegalStateException("Already Executed");
    default:
      throw new IllegalStateException("Unknown state");
  }
  state.set(ACTIVE);
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:17,
代码来源:RealApolloQueryWatcher.java

示例6: terminate

点赞 3

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
synchronized Optional<ApolloCall.Callback<T>> terminate() {
  switch (state.get()) {
    case ACTIVE:
      tracker.unregisterQueryWatcher(this);
      state.set(TERMINATED);
      return Optional.fromNullable(originalCallback.getAndSet(null));
    case CANCELED:
      return Optional.fromNullable(originalCallback.getAndSet(null));
    case IDLE:
    case TERMINATED:
      throw new IllegalStateException(
          CallState.IllegalStateMessage.forCurrentState(state.get()).expected(ACTIVE, CANCELED));
    default:
      throw new IllegalStateException("Unknown state");
  }
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:17,
代码来源:RealApolloQueryWatcher.java

示例7: loadPinnedRepos

点赞 2

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
private void loadPinnedRepos() {
    pinnedState.setValue(State.loading(null));
    ApolloCall<GetPinnedReposQuery.Data> apolloCall = apolloClient.query(GetPinnedReposQuery.builder()
                    .login(user)
                    .build());
    RxHelper.getObservable(Rx2Apollo.from(apolloCall))
            .filter(dataResponse -> !dataResponse.hasErrors())
            .flatMap(dataResponse -> {
                GetPinnedReposQuery.Data data = dataResponse.data();
                if (data != null && data.user() != null) {
                    return Observable.fromIterable(data.user().pinnedRepositories().edges());
                }
                return Observable.empty();
            })
            .map(GetPinnedReposQuery.Edge::node)
            .toList()
            .toObservable()
            .subscribe(nodes1 -> {
                pinnedNodes.setValue(nodes1);
                if (nodes1.size() > 0) {
                    pinnedState.setValue(State.success(null));
                } else {
                    pinnedState.setValue(State.error(null));
                }
            }, throwable -> {
                throwable.printStackTrace();
                pinnedState.setValue(State.error(null));
            });
}
 

开发者ID:duyp,
项目名称:mvvm-template,
代码行数:30,
代码来源:OverviewViewModel.java

示例8: checkIsIdleNow_whenCallIsQueued

点赞 2

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
@Test
public void checkIsIdleNow_whenCallIsQueued() throws IOException, TimeoutException, InterruptedException {
  server.enqueue(mockResponse());

  final CountDownLatch latch = new CountDownLatch(1);

  ExecutorService executorService = Executors.newFixedThreadPool(1);

  apolloClient = ApolloClient.builder()
      .okHttpClient(okHttpClient)
      .dispatcher(executorService)
      .serverUrl(server.url("/"))
      .build();

  idlingResource = ApolloIdlingResource.create(IDLING_RESOURCE_NAME, apolloClient);
  assertThat(idlingResource.isIdleNow()).isTrue();

  apolloClient.query(EMPTY_QUERY).enqueue(new ApolloCall.Callback<Object>() {
    @Override public void onResponse(@Nonnull Response<Object> response) {
      latch.countDown();
    }

    @Override public void onFailure(@Nonnull ApolloException e) {
      throw new AssertionError("This callback can't be called.");
    }
  });
  assertThat(idlingResource.isIdleNow()).isFalse();

  latch.await(TIME_OUT_SECONDS, TimeUnit.SECONDS);

  executorService.shutdown();
  executorService.awaitTermination(TIME_OUT_SECONDS, TimeUnit.SECONDS);
  Thread.sleep(100);
  assertThat(idlingResource.isIdleNow()).isTrue();
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:36,
代码来源:ApolloIdlingResourceTest.java

示例9: onStatusEvent

点赞 2

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
@Override public void onStatusEvent(@Nonnull ApolloCall.StatusEvent event) {
  if (event == ApolloCall.StatusEvent.COMPLETED) {
    if (completed) throw new IllegalStateException("onCompleted already called Do not reuse tracking callback.");
    completed = true;
    completedOrErrorLatch.countDown();
  }
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:8,
代码来源:BaseFetcherTest.java

示例10: registerCall

点赞 2

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
/**
 * <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");
  }
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:17,
代码来源:ApolloCallTracker.java

示例11: unregisterCall

点赞 2

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
/**
 * <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");
  }
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:22,
代码来源:ApolloCallTracker.java

示例12: enqueueAndWatch

点赞 2

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
@Override public ApolloQueryWatcher<T> enqueueAndWatch(@Nullable final ApolloCall.Callback<T> callback) {
  try {
    activate(Optional.fromNullable(callback));
  } catch (ApolloCanceledException e) {
    if (callback != null) {
      callback.onCanceledError(e);
    } else {
      logger.e(e, "Operation: %s was canceled", operation().name().name());
    }
    return this;
  }
  activeCall.enqueue(callbackProxy());
  return this;
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:15,
代码来源:RealApolloQueryWatcher.java

示例13: responseCallback

点赞 2

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
synchronized Optional<ApolloCall.Callback<T>> responseCallback() {
  switch (state.get()) {
    case ACTIVE:
    case CANCELED:
      return Optional.fromNullable(originalCallback.get());
    case IDLE:
    case TERMINATED:
      throw new IllegalStateException(
          CallState.IllegalStateMessage.forCurrentState(state.get()).expected(ACTIVE, CANCELED));
    default:
      throw new IllegalStateException("Unknown state");
  }
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:14,
代码来源:RealApolloQueryWatcher.java

示例14: from

点赞 2

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
/**
 * Converts an {@link ApolloQueryWatcher} into an Observable.
 *
 * @param watcher          the ApolloQueryWatcher to convert
 * @param backpressureMode the back pressure strategy to apply to the observable source.
 * @param <T>              the value type
 * @return the converted Observable
 */
@Nonnull public static <T> Observable<Response<T>> from(@Nonnull final ApolloQueryWatcher<T> watcher,
    @Nonnull Emitter.BackpressureMode backpressureMode) {
  checkNotNull(backpressureMode, "backpressureMode == null");
  checkNotNull(watcher, "watcher == null");
  return Observable.create(new Action1<Emitter<Response<T>>>() {
    @Override public void call(final Emitter<Response<T>> emitter) {
      final AtomicBoolean canceled = new AtomicBoolean();
      emitter.setCancellation(new Cancellable() {
        @Override public void cancel() throws Exception {
          canceled.set(true);
          watcher.cancel();
        }
      });
      watcher.enqueueAndWatch(new ApolloCall.Callback<T>() {
        @Override public void onResponse(@Nonnull Response<T> response) {
          if (!canceled.get()) {
            emitter.onNext(response);
          }
        }

        @Override public void onFailure(@Nonnull ApolloException e) {
          Exceptions.throwIfFatal(e);
          if (!canceled.get()) {
            emitter.onError(e);
          }
        }
      });
    }
  }, backpressureMode);
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:39,
代码来源:RxApollo.java

示例15: rxApolloCall

点赞 2

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
public static <T> Single<T> rxApolloCall(final ApolloCall<T> call) {
  return Observable.create((ObservableOnSubscribe<Response<T>>) emitter -> {
    cancelOnObservableDisposed(emitter, call);
    call.enqueue(new ApolloCall.Callback<T>() {
      @Override public void onResponse(@Nonnull Response<T> response) {
        if (!emitter.isDisposed()) {
          emitter.onNext(response);
        }
      }

      @Override public void onFailure(@Nonnull ApolloException e) {
        Exceptions.throwIfFatal(e);
        if (!emitter.isDisposed()) {
          emitter.onError(e);
        }
      }

      @Override public void onStatusEvent(@Nonnull ApolloCall.StatusEvent event) {
        if (event == ApolloCall.StatusEvent.COMPLETED && !emitter.isDisposed()) {
          emitter.onComplete();
        }
      }
    });
  })
    .firstOrError()
    .compose(queryResponseDataTransformer());
}
 

开发者ID:Shopify,
项目名称:mobile-buy-sdk-android,
代码行数:28,
代码来源:RxUtil.java

示例16: refetchWatchers

点赞 2

import com.apollographql.apollo.ApolloCall; //导入依赖的package包/类
@Test public void refetchWatchers() throws Exception {
  server.enqueue(mockResponse("ReviewsEmpireEpisodeResponse.json"));
  server.enqueue(mockResponse("CreateReviewResponse.json"));
  server.enqueue(mockResponse("ReviewsEmpireEpisodeResponseUpdated.json"));

  final NamedCountDownLatch countDownBeforeMutationLatch = new NamedCountDownLatch("before_mutation", 1);
  final NamedCountDownLatch countDownRefetchLatch = new NamedCountDownLatch("refetch", 2);
  final AtomicReference<Response<ReviewsByEpisodeQuery.Data>> empireReviewsWatchResponse = new AtomicReference<>();
  ApolloQueryWatcher<ReviewsByEpisodeQuery.Data> queryWatcher = apolloClient.query(new ReviewsByEpisodeQuery(Episode.EMPIRE))
      .watcher()
      .refetchResponseFetcher(NETWORK_FIRST)
      .enqueueAndWatch(new ApolloCall.Callback<ReviewsByEpisodeQuery.Data>() {
        @Override public void onResponse(@Nonnull Response<ReviewsByEpisodeQuery.Data> response) {
          empireReviewsWatchResponse.set(response);
          countDownBeforeMutationLatch.countDown();
          countDownRefetchLatch.countDown();
        }

        @Override public void onFailure(@Nonnull ApolloException e) {
        }
      });

  countDownBeforeMutationLatch.awaitOrThrowWithTimeout(TIME_OUT_SECONDS, TimeUnit.SECONDS);
  CreateReviewMutation mutation = new CreateReviewMutation(
      Episode.EMPIRE,
      ReviewInput.builder().stars(5).commentary("Awesome").favoriteColor(ColorInput.builder().build()).build()
  );
  Rx2Apollo
      .from(apolloClient.mutate(mutation).refetchQueries(queryWatcher.operation().name()))
      .test()
      .awaitDone(TIME_OUT_SECONDS, TimeUnit.SECONDS);
  countDownRefetchLatch.awaitOrThrowWithTimeout(TIME_OUT_SECONDS, TimeUnit.SECONDS);
  assertThat(server.getRequestCount()).isEqualTo(3);

  Response<ReviewsByEpisodeQuery.Data> empireReviewsQueryResponse = empireReviewsWatchResponse.get();
  assertThat(empireReviewsQueryResponse.data().reviews()).hasSize(4);
  assertThat(empireReviewsQueryResponse.data().reviews().get(3).stars()).isEqualTo(5);
  assertThat(empireReviewsQueryResponse.data().reviews().get(3).commentary()).isEqualTo("Awesome");

  queryWatcher.cancel();
}
 

开发者ID:apollographql,
项目名称:apollo-android,
代码行数:42,
代码来源:QueryRefetchTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)