public <D extends Mutation.Data, T, V extends Mutation.Variables> AppSyncMutationCall<T> mutate(@Nonnull Mutation<D, T, V> mutation) { return mutate(mutation, false); }
/** * Provides the ability to sync using a baseQuery and a refresh interval * * @param baseQuery the base query to get the baseline state * @param baseQueryCallback callback to handle the baseQuery results * @param baseRefreshIntervalInSeconds time duration (specified in seconds) when the base query will be re-run to get an updated baseline state. * @param <D> * @param <T> * @param <V> * @return a Cancelable object that can be used later to cancel the sync operation by calling the cancel() method */ public <D extends Query.Data, T, V extends Query.Variables> Cancelable sync( @Nonnull Query<D, T, V> baseQuery, GraphQLCall.Callback<Query.Data> baseQueryCallback, long baseRefreshIntervalInSeconds) { return this.sync(baseQuery, baseQueryCallback,null, null,null, null, baseRefreshIntervalInSeconds); }
awsAppSyncClient.query(baseQuery) .responseFetcher(fetchPolicy) .enqueue(cb);
public synchronized static AWSAppSyncClient getInstance(Context context) { if (client == null) { client = AWSAppSyncClient.builder() .context(context) .apiKey(new BasicAPIKeyAuthProvider(Constants.APPSYNC_API_KEY)) // For use with IAM/Cognito authorization .region(Constants.APPSYNC_REGION) .serverUrl(Constants.APPSYNC_API_URL) .persistentMutationsCallback(new PersistentMutationsCallback() { @Override public void onResponse(PersistentMutationsResponse response) { Log.d("NOTERROR", response.getMutationClassName()); } @Override public void onFailure(PersistentMutationsError error) { Log.e("TAG", error.getMutationClassName()); Log.e("TAG", "Error", error.getException()); } }) .build(); } return client; } }
AWSAppSyncClient awsAppSyncClient = AppSyncTestSetupHelper.createAppSyncClientWithIAM(true,2*1000); assertNotNull(awsAppSyncClient); assertTrue(awsAppSyncClient.isMutationQueueEmpty()); AppSyncMutationCall call = awsAppSyncClient.mutate(addPostMutation, expected); assertFalse(awsAppSyncClient.isMutationQueueEmpty()); awsAppSyncClient.clearMutationQueue(); assertTrue(awsAppSyncClient.isMutationQueueEmpty());
deltaSyncSubscriptionWatcher = awsAppSyncClient.subscribe(subscription); deltaSyncSubscriptionWatcher.execute(scb);
AWSAppSyncClient awsAppSyncClient = AppSyncTestSetupHelper.createAppSyncClientWithIAM(true,2*1000); assertNotNull(awsAppSyncClient); assertTrue(awsAppSyncClient.isMutationQueueEmpty()); final AppSyncMutationCall call = awsAppSyncClient.mutate(addPostMutation, expected); assertFalse(awsAppSyncClient.isMutationQueueEmpty()); try { addCountdownlatch.await(60, TimeUnit.SECONDS); iex.printStackTrace(); assertTrue(awsAppSyncClient.isMutationQueueEmpty());
private void updateListPostsQueryCache() { List<ListPostsQuery.ListPost> items = new ArrayList<>(); items.addAll(allPosts.values()); ListPostsQuery.Data data = new ListPostsQuery.Data(items); ClientFactory.getInstance(display.getApplicationContext()).getStore() .write(listPostsQuery, data).enqueue(null); }
return new AWSAppSyncClient(this);
appSyncSigV4SignerInterceptor = new AppSyncSigV4SignerInterceptor(builder.mOidcAuthProvider); } else if (builder.mApiKey != null) { appSyncSigV4SignerInterceptor = new AppSyncSigV4SignerInterceptor(builder.mApiKey, builder.mRegion.getName(), getClientSubscriptionUUID(builder.mApiKey.getAPIKey())); } else { throw new RuntimeException("Client requires credentials. Please use #apiKey() #credentialsProvider() or #cognitoUserPoolsAuthProvider() to set the credentials.");
S3ObjectManager s3ObjectManager = new S3ObjectManagerImplementation((s3Client)); return AWSAppSyncClient.builder() .context(InstrumentationRegistry.getContext()) .credentialsProvider(credentialsProvider)
AppSyncSubscriptionCall subscriptionWatcher = awsAppSyncClient1.subscribe(onCreatePostSubscription); subscriptionWatcher.execute(onCreatePostSubscriptionCallback); Log.d(TAG, "Subscribed and setup callback handler.");
public <D extends Mutation.Data, T, V extends Mutation.Variables> AppSyncMutationCall<T> mutate(@Nonnull Mutation<D, T, V> mutation, @Nonnull D withOptimisticUpdates) { return mutate(mutation, withOptimisticUpdates, false); }
S3ObjectManager s3ObjectManager = new S3ObjectManagerImplementation((s3Client)); return AWSAppSyncClient.builder() .context(InstrumentationRegistry.getContext()) .apiKey(provider)
/** * Provides the ability to sync using a baseQuery and Subscription * @param baseQuery the base query to get the baseline state * @param baseQueryCallback callback to handle the baseQuery results * @param subscription subscription to get changes on the fly * @param subscriptionCallback callback to handle the subscription messages * @param <D> * @param <T> * @param <V> * @return a Cancelable object that can be used later to cancel the sync operation by calling the cancel() method */ public <D extends Query.Data, T, V extends Query.Variables> Cancelable sync( @Nonnull Query<D, T, V> baseQuery, GraphQLCall.Callback<Query.Data> baseQueryCallback, Subscription<D,T,V> subscription, AppSyncSubscriptionCall.Callback subscriptionCallback ) { return this.sync(baseQuery, baseQueryCallback, subscription, subscriptionCallback, null, null, 0 ); }
AppSyncSubscriptionCall onCreatePostSubscriptionWatcher = awsAppSyncClient.subscribe(onCreatePostSubscription); onCreatePostSubscriptionWatcher.execute(onCreatePostSubscriptionCallback); Log.d(TAG, "Subscribed and setup callback handler.");
awsAppSyncClient.query(adjust(deltaQuery)) .responseFetcher(AppSyncResponseFetchers.NETWORK_ONLY) .enqueue(dcb);
public <D extends Mutation.Data, T, V extends Mutation.Variables> void retryConflictMutation(@Nonnull Mutation<D, T, V> mutation, String uniqueIdentifierForOriginalMutation) { //Remove callback from map. This will return null for persistent offline mutations InterceptorCallback callback = (InterceptorCallback) callbackMapForInMemoryMutations.remove(uniqueIdentifierForOriginalMutation); if (callback != null ) { //Put the callback in with the mutation.toString() as the key. This will be picked up to route the the mutation results // back to the callback later. Log.d(TAG, "Proceeding with retry for inMemory offline mutation [" + uniqueIdentifierForOriginalMutation + "]"); callbackMapForInMemoryMutations.put(mutation.toString(), callback); } else { // put in details of persistent mutation. //TODO: Check if this logic is required. Log.d(TAG, "Proceeding with retry for persistent offline mutation [" + uniqueIdentifierForOriginalMutation + "]"); if (persistentOfflineMutationObjectMap.isEmpty()) { Log.d(TAG, "Populating mutations map."); persistentOfflineMutationObjectMap.putAll(appSyncOfflineMutationManager.persistentOfflineMutationManager.persistentOfflineMutationObjectMap); } PersistentOfflineMutationObject object = persistentOfflineMutationObjectMap.remove(uniqueIdentifierForOriginalMutation); persistentOfflineMutationObjectMap.put(mutation.toString(), object); } appSyncClient.mutate(mutation, true).enqueue(null); }
@Test public void testDefault() { awsConfiguration.setConfiguration("Default"); final AWSAppSyncClient awsAppSyncClient = AWSAppSyncClient.builder() .context(shadowContext) .awsConfiguration(awsConfiguration) .build(); assertNotNull(awsAppSyncClient); }
/** * Provides the ability to sync using a baseQuery, deltaQuery, and a refresh interval * @param baseQuery the base query to get the baseline state * @param baseQueryCallback callback to handle the baseQuery results * @param deltaQuery the catchup query * @param deltaQueryCallback callback to handle the deltaQuery results * @param baseRefreshIntervalInSeconds time duration (specified in seconds) when the base query will be re-run to get an updated baseline state. * @param <D> * @param <T> * @param <V> * @return a Cancelable object that can be used later to cancel the sync operation by calling the cancel() method */ public <D extends Query.Data, T, V extends Query.Variables> Cancelable sync( @Nonnull Query<D, T, V> baseQuery, GraphQLCall.Callback<Query.Data> baseQueryCallback, Query<D,T,V> deltaQuery, GraphQLCall.Callback<Query.Data> deltaQueryCallback, long baseRefreshIntervalInSeconds) { return this.sync(baseQuery, baseQueryCallback, null, null, deltaQuery, deltaQueryCallback, baseRefreshIntervalInSeconds); }