use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class SubscriptionInstrumentationTest method testAddSubscriptionWithIAMAuthModelForNullPatching.
@Test
public void testAddSubscriptionWithIAMAuthModelForNullPatching() {
AWSAppSyncClient awsAppSyncClient = AWSAppSyncClients.withIAMFromAWSConfiguration();
final String title = "22 Acacia Avenue";
final String author = "Maiden @ " + System.currentTimeMillis();
final String url = "1998 Remastered ";
final String content = "If you are feeling down, depressed and lonely @" + System.currentTimeMillis();
AppSyncSubscriptionCall<OnCreatePostSubscription.Data> onCreatePostSubscriptionCall = awsAppSyncClient.subscribe(OnCreatePostSubscription.builder().build());
LatchedSubscriptionCallback<OnCreatePostSubscription.Data> onCreatePostCallback = LatchedSubscriptionCallback.instance();
onCreatePostSubscriptionCall.execute(onCreatePostCallback);
Log.d(TAG, "Subscribed and setup callback handler.");
// Sleep for a while to make sure the subscription goes through
Sleep.milliseconds(REASONABLE_WAIT_TIME_MS);
// Try to create post using only the fields that are required for success.
Posts.addRequiredFieldsOnly(awsAppSyncClient, title, author, url, content);
Log.d(TAG, "Added Post using addPostRequireFieldsOnlyMutation ");
onCreatePostCallback.awaitNextSuccessfulResponse();
// Try to create a post, by supplying an incomplete set of parameters.
// Expect errors in the GraphQL response.
Posts.addMissingRequiredFields(awsAppSyncClient, title, author + System.currentTimeMillis(), url, content);
Log.d(TAG, "Added Post using addPostMissingRequiredFieldsMutation");
assertTrue(onCreatePostCallback.awaitNextResponse().hasErrors());
// Cancel the subscription and expect a completion callback.
onCreatePostSubscriptionCall.cancel();
onCreatePostCallback.awaitCompletion();
}
use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class Posts method list.
public static Map<String, Response<AllPostsQuery.Data>> list(AWSAppSyncClient client, ResponseFetcher responseFetcher) {
int expectedResponseCount = responseFetcher.equals(AppSyncResponseFetchers.CACHE_AND_NETWORK) ? 2 : 1;
CountDownLatch queryCountDownLatch = new CountDownLatch(expectedResponseCount);
Log.d(TAG, "Calling Query listPosts with responseFetcher: " + responseFetcher.toString());
Map<String, Response<AllPostsQuery.Data>> listPostsQueryResponses = new HashMap<>();
client.query(AllPostsQuery.builder().build()).responseFetcher(responseFetcher).enqueue(DelegatingGraphQLCallback.to(response -> {
if (response.fromCache()) {
listPostsQueryResponses.put("CACHE", response);
} else {
listPostsQueryResponses.put("NETWORK", response);
}
queryCountDownLatch.countDown();
}, failure -> {
failure.printStackTrace();
queryCountDownLatch.countDown();
}));
Await.latch(queryCountDownLatch);
if (responseFetcher.equals(AppSyncResponseFetchers.CACHE_AND_NETWORK)) {
assertNotNull(listPostsQueryResponses.get("CACHE"));
assertNotNull(listPostsQueryResponses.get("NETWORK"));
assertEquals(2, listPostsQueryResponses.size());
} else {
assertEquals(1, listPostsQueryResponses.size());
}
return listPostsQueryResponses;
}
use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class AWSAppSyncClients method withUserPools2FromAWSConfiguration.
@NonNull
public static AWSAppSyncClient withUserPools2FromAWSConfiguration(String idTokenStringForCustomCognitoUserPool, ResponseFetcher responseFetcher) {
// Amazon Cognito User Pools - Custom CognitoUserPool
String clientDatabasePrefix = null;
String clientName = null;
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
awsConfiguration.setConfiguration("MultiAuthAndroidIntegTestApp_AMAZON_COGNITO_USER_POOLS_2");
try {
clientDatabasePrefix = awsConfiguration.optJsonObject("AppSync").getString("ClientDatabasePrefix");
clientName = awsConfiguration.optJsonObject("AppSync").getString("AuthMode");
} catch (JSONException e) {
e.printStackTrace();
}
AWSAppSyncClient.Builder awsAppSyncClientBuilder4 = AWSAppSyncClient.builder().context(getTargetContext()).cognitoUserPoolsAuthProvider(() -> idTokenStringForCustomCognitoUserPool).awsConfiguration(awsConfiguration).useClientDatabasePrefix(true).defaultResponseFetcher(responseFetcher);
AWSAppSyncClient awsAppSyncClient4 = awsAppSyncClientBuilder4.build();
validateAppSyncClient(awsAppSyncClient4, clientDatabasePrefix, clientName);
return awsAppSyncClient4;
}
Aggregations