Java Code Examples for com.apollographql.apollo.api.Operation#Data
The following examples show how to use
com.apollographql.apollo.api.Operation#Data .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubscriptionManagerTest.java From apollo-android with MIT License | 6 votes |
@Test public void unsubscribeOnComplete() { SubscriptionManagerCallbackAdapter<Operation.Data> subscriptionManagerCallback1 = new SubscriptionManagerCallbackAdapter<>(); subscriptionManager.subscribe(subscription1, subscriptionManagerCallback1); SubscriptionManagerCallbackAdapter<Operation.Data> subscriptionManagerCallback2 = new SubscriptionManagerCallbackAdapter<>(); subscriptionManager.subscribe(subscription2, subscriptionManagerCallback2); final List<UUID> subscriptionIds = new ArrayList<>(subscriptionManager.subscriptions.keySet()); subscriptionTransportFactory.callback.onConnected(); subscriptionTransportFactory.callback.onMessage(new OperationServerMessage.ConnectionAcknowledge()); subscriptionTransportFactory.callback.onMessage(new OperationServerMessage.Complete(subscriptionIds.get(0).toString())); assertThat(subscriptionManagerCallback1.completed).isTrue(); assertThat(subscriptionManager.subscriptions).hasSize(1); assertThat(subscriptionManagerCallback2.completed).isFalse(); }
Example 2
Source File: RealApolloStore.java From apollo-android with MIT License | 6 votes |
<D extends Operation.Data, T, V extends Operation.Variables> T doRead(final Operation<D, T, V> operation) { return readTransaction(new Transaction<ReadableStore, T>() { @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)); } }); }
Example 3
Source File: ApolloClient.java From apollo-android with MIT License | 6 votes |
private <D extends Operation.Data, T, V extends Operation.Variables> RealApolloCall<T> newCall( @NotNull Operation<D, T, V> operation) { return RealApolloCall.<T>builder() .operation(operation) .serverUrl(serverUrl) .httpCallFactory(httpCallFactory) .httpCache(httpCache) .httpCachePolicy(defaultHttpCachePolicy) .responseFieldMapperFactory(responseFieldMapperFactory) .scalarTypeAdapters(scalarTypeAdapters) .apolloStore(apolloStore) .responseFetcher(defaultResponseFetcher) .cacheHeaders(defaultCacheHeaders) .dispatcher(dispatcher) .logger(logger) .applicationInterceptors(applicationInterceptors) .applicationInterceptorFactories(applicationInterceptorFactories) .tracker(tracker) .refetchQueries(Collections.<Query>emptyList()) .refetchQueryNames(Collections.<OperationName>emptyList()) .enableAutoPersistedQueries(enableAutoPersistedQueries) .useHttpGetMethodForQueries(useHttpGetMethodForQueries) .useHttpGetMethodForPersistedQueries(useHttpGetMethodForPersistedQueries) .build(); }
Example 4
Source File: SubscriptionManagerTest.java From apollo-android with MIT License | 6 votes |
@Test public void unsubscribeOnError() { SubscriptionManagerCallbackAdapter<Operation.Data> subscriptionManagerCallback1 = new SubscriptionManagerCallbackAdapter<>(); subscriptionManager.subscribe(subscription1, subscriptionManagerCallback1); SubscriptionManagerCallbackAdapter<Operation.Data> subscriptionManagerCallback2 = new SubscriptionManagerCallbackAdapter<>(); subscriptionManager.subscribe(subscription2, subscriptionManagerCallback2); final List<UUID> subscriptionIds = new ArrayList<>(subscriptionManager.subscriptions.keySet()); subscriptionTransportFactory.callback.onConnected(); subscriptionTransportFactory.callback.onMessage(new OperationServerMessage.ConnectionAcknowledge()); subscriptionTransportFactory.callback.onMessage(new OperationServerMessage.Error(subscriptionIds.get(0).toString(), new UnmodifiableMapBuilder<String, Object>().put("key1", "value1").put("key2", "value2").build())); assertThat(subscriptionManagerCallback1.error).isInstanceOf(ApolloSubscriptionServerException.class); assertThat(((ApolloSubscriptionServerException) subscriptionManagerCallback1.error).errorPayload).containsEntry("key1", "value1"); assertThat(((ApolloSubscriptionServerException) subscriptionManagerCallback1.error).errorPayload).containsEntry("key2", "value2"); assertThat(subscriptionManager.subscriptions).hasSize(1); assertThat(subscriptionManagerCallback2.completed).isFalse(); }
Example 5
Source File: SubscriptionManagerTest.java From apollo-android with MIT License | 5 votes |
@Test public void connectionTerminated() { SubscriptionManagerCallbackAdapter<Operation.Data> subscriptionManagerCallback = new SubscriptionManagerCallbackAdapter<>(); subscriptionManager.subscribe(subscription1, subscriptionManagerCallback); subscriptionTransportFactory.callback.onConnected(); subscriptionTransportFactory.callback.onMessage(new OperationServerMessage.ConnectionAcknowledge()); assertThat(subscriptionManager.state).isEqualTo(SubscriptionManagerState.ACTIVE); subscriptionTransportFactory.callback.onClosed(); assertThat(subscriptionManager.state).isEqualTo(SubscriptionManagerState.DISCONNECTED); assertThat(subscriptionManagerCallback.terminated).isTrue(); }
Example 6
Source File: OperationResponseParserTest.java From apollo-android with MIT License | 5 votes |
@Test public void validateNullDataFieldInPayload() { OperationResponseParser<Operation.Data, String> parser = new OperationResponseParser<>( mock(TestOperation.class), mock(ResponseFieldMapper.class), new ScalarTypeAdapters(new HashMap<ScalarType, CustomTypeAdapter<?>>()) ); Map<String, Object> payload = new HashMap<>(); parser.parse(payload); payload.put("data", null); parser.parse(payload); }
Example 7
Source File: SubscriptionManagerTest.java From apollo-android with MIT License | 5 votes |
@Test public void subscriptionWhenStopped() { subscriptionManager.stop(); SubscriptionManagerCallbackAdapter<Operation.Data> subscriptionManagerCallback = new SubscriptionManagerCallbackAdapter<>(); subscriptionManager.subscribe(subscription1, subscriptionManagerCallback); assertThat(subscriptionManager.state).isEqualTo(SubscriptionManagerState.STOPPED); assertThat(subscriptionManagerCallback.error).isInstanceOf(ApolloSubscriptionException.class); assertThat(subscriptionManagerCallback.error.getMessage()).startsWith("Illegal state: STOPPED"); }
Example 8
Source File: RealApolloStore.java From apollo-android with MIT License | 5 votes |
@NotNull @Override public <D extends Operation.Data, T, V extends Operation.Variables> ApolloStoreOperation<Boolean> writeOptimisticUpdatesAndPublish(@NotNull final Operation<D, T, V> operation, @NotNull final D operationData, @NotNull final UUID mutationId) { return new ApolloStoreOperation<Boolean>(dispatcher) { @Override protected Boolean perform() { Set<String> changedKeys = doWrite(operation, operationData, true, mutationId); publish(changedKeys); return Boolean.TRUE; } }; }
Example 9
Source File: RealApolloStore.java From apollo-android with MIT License | 5 votes |
@NotNull @Override public <D extends Operation.Data, T, V extends Operation.Variables> ApolloStoreOperation<Set<String>> writeOptimisticUpdates(@NotNull final Operation<D, T, V> operation, @NotNull final D operationData, @NotNull final UUID mutationId) { return new ApolloStoreOperation<Set<String>>(dispatcher) { @Override protected Set<String> perform() { return doWrite(operation, operationData, true, mutationId); } }; }
Example 10
Source File: RealApolloStore.java From apollo-android with MIT License | 5 votes |
@Override @NotNull public <D extends Operation.Data, T, V extends Operation.Variables> ApolloStoreOperation<Boolean> writeAndPublish(@NotNull final Operation<D, T, V> operation, @NotNull final D operationData) { return new ApolloStoreOperation<Boolean>(dispatcher) { @Override protected Boolean perform() { Set<String> changedKeys = doWrite(operation, operationData, false, null); publish(changedKeys); return Boolean.TRUE; } }; }
Example 11
Source File: RealApolloStore.java From apollo-android with MIT License | 5 votes |
@Override @NotNull public <D extends Operation.Data, T, V extends Operation.Variables> ApolloStoreOperation<Response<T>> read(@NotNull final Operation<D, T, V> operation, @NotNull final ResponseFieldMapper<D> responseFieldMapper, @NotNull final ResponseNormalizer<Record> responseNormalizer, @NotNull final CacheHeaders cacheHeaders) { checkNotNull(operation, "operation == null"); checkNotNull(responseNormalizer, "responseNormalizer == null"); return new ApolloStoreOperation<Response<T>>(dispatcher) { @Override protected Response<T> perform() { return doRead(operation, responseFieldMapper, responseNormalizer, cacheHeaders); } }; }
Example 12
Source File: SubscriptionManagerTest.java From apollo-android with MIT License | 5 votes |
@Override public ResponseFieldMapper<Data> responseFieldMapper() { return new ResponseFieldMapper<Data>() { @Override public Data map(ResponseReader responseReader) { return new Operation.Data() { @Override public ResponseFieldMarshaller marshaller() { throw new UnsupportedOperationException(); } }; } }; }
Example 13
Source File: ApolloInterceptor.java From apollo-android with MIT License | 5 votes |
InterceptorRequest(Operation operation, CacheHeaders cacheHeaders, RequestHeaders requestHeaders, Optional<Operation.Data> optimisticUpdates, boolean fetchFromCache, boolean sendQueryDocument, boolean useHttpGetMethodForQueries, boolean autoPersistQueries) { this.operation = operation; this.cacheHeaders = cacheHeaders; this.requestHeaders = requestHeaders; this.optimisticUpdates = optimisticUpdates; this.fetchFromCache = fetchFromCache; this.sendQueryDocument = sendQueryDocument; this.useHttpGetMethodForQueries = useHttpGetMethodForQueries; this.autoPersistQueries = autoPersistQueries; }
Example 14
Source File: SubscriptionManagerTest.java From apollo-android with MIT License | 5 votes |
@Test public void duplicateSubscriptions() { SubscriptionManagerCallbackAdapter<Operation.Data> subscriptionManagerCallback1 = new SubscriptionManagerCallbackAdapter<>(); subscriptionManager.subscribe(subscription1, subscriptionManagerCallback1); SubscriptionManagerCallbackAdapter<Operation.Data> subscriptionManagerCallback2 = new SubscriptionManagerCallbackAdapter<>(); subscriptionManager.subscribe(subscription1, subscriptionManagerCallback2); assertThat(subscriptionManagerCallback2.error).isNull(); }
Example 15
Source File: ApolloClient.java From apollo-android with MIT License | 4 votes |
@Override public <D extends Operation.Data, T, V extends Operation.Variables> ApolloPrefetch prefetch( @NotNull Operation<D, T, V> operation) { return new RealApolloPrefetch(operation, serverUrl, httpCallFactory, scalarTypeAdapters, dispatcher, logger, tracker); }
Example 16
Source File: NoOpApolloStore.java From apollo-android with MIT License | 4 votes |
@NotNull @Override public <D extends Operation.Data, T, V extends Operation.Variables> ApolloStoreOperation<Boolean> writeOptimisticUpdatesAndPublish(@NotNull Operation<D, T, V> operation, @NotNull D operationData, @NotNull UUID mutationId) { return ApolloStoreOperation.emptyOperation(Boolean.FALSE); }
Example 17
Source File: NoOpApolloStore.java From apollo-android with MIT License | 4 votes |
@NotNull @Override public <D extends Operation.Data, T, V extends Operation.Variables> ApolloStoreOperation<Boolean> writeAndPublish( @NotNull Operation<D, T, V> operation, @NotNull D operationData) { return ApolloStoreOperation.emptyOperation(Boolean.FALSE); }
Example 18
Source File: NoOpApolloStore.java From apollo-android with MIT License | 4 votes |
@NotNull @Override public <D extends Operation.Data, T, V extends Operation.Variables> ApolloStoreOperation<Set<String>> write( @NotNull Operation<D, T, V> operation, @NotNull D operationData) { return ApolloStoreOperation.emptyOperation(Collections.<String>emptySet()); }
Example 19
Source File: NoOpApolloStore.java From apollo-android with MIT License | 4 votes |
@NotNull @Override public <D extends Operation.Data, T, V extends Operation.Variables> ApolloStoreOperation<T> read( @NotNull Operation<D, T, V> operation) { return ApolloStoreOperation.emptyOperation(null); }
Example 20
Source File: ApolloPrefetch.java From apollo-android with MIT License | 2 votes |
/** * Creates the ApolloPrefetch by wrapping the operation object inside. * * @param operation the operation which needs to be performed * @return The ApolloPrefetch object with the wrapped operation object */ <D extends Operation.Data, T, V extends Operation.Variables> ApolloPrefetch prefetch( @NotNull Operation<D, T, V> operation);