Search in sources :

Example 1 with AuthModeStrategyType

use of com.amplifyframework.api.aws.AuthModeStrategyType in project amplify-android by aws-amplify.

the class AppSyncClient method subscription.

private <T extends Model> Cancelable subscription(SubscriptionType subscriptionType, ModelSchema modelSchema, Consumer<String> onSubscriptionStarted, Consumer<GraphQLResponse<ModelWithMetadata<T>>> onNextResponse, Consumer<DataStoreException> onSubscriptionFailure, Action onSubscriptionCompleted) {
    final GraphQLRequest<ModelWithMetadata<T>> request;
    try {
        request = AppSyncRequestFactory.buildSubscriptionRequest(modelSchema, subscriptionType, authModeStrategyType);
    } catch (DataStoreException requestGenerationException) {
        onSubscriptionFailure.accept(requestGenerationException);
        return new NoOpCancelable();
    }
    final Consumer<GraphQLResponse<ModelWithMetadata<T>>> responseConsumer = response -> {
        if (response.hasErrors()) {
            onSubscriptionFailure.accept(new DataStoreException.GraphQLResponseException("Subscription error for " + modelSchema.getName() + ": " + response.getErrors(), response.getErrors()));
        } else {
            onNextResponse.accept(response);
        }
    };
    final Consumer<ApiException> failureConsumer = failure -> onSubscriptionFailure.accept(new DataStoreException("Error during subscription.", failure, "Evaluate details."));
    final Cancelable cancelable = api.subscribe(request, onSubscriptionStarted, responseConsumer, failureConsumer, onSubscriptionCompleted);
    if (cancelable != null) {
        return cancelable;
    }
    return new NoOpCancelable();
}
Also used : Amplify(com.amplifyframework.core.Amplify) AmplifyException(com.amplifyframework.AmplifyException) NonNull(androidx.annotation.NonNull) QueryPredicates(com.amplifyframework.core.model.query.predicate.QueryPredicates) GraphQLRequest(com.amplifyframework.api.graphql.GraphQLRequest) Model(com.amplifyframework.core.model.Model) Action(com.amplifyframework.core.Action) ApiException(com.amplifyframework.api.ApiException) Logger(com.amplifyframework.logging.Logger) GraphQLBehavior(com.amplifyframework.api.graphql.GraphQLBehavior) DataStoreException(com.amplifyframework.datastore.DataStoreException) Consumer(com.amplifyframework.core.Consumer) Nullable(androidx.annotation.Nullable) Cancelable(com.amplifyframework.core.async.Cancelable) SubscriptionType(com.amplifyframework.api.graphql.SubscriptionType) AuthModeStrategyType(com.amplifyframework.api.aws.AuthModeStrategyType) NoOpCancelable(com.amplifyframework.core.async.NoOpCancelable) ModelSchema(com.amplifyframework.core.model.ModelSchema) GraphQLResponse(com.amplifyframework.api.graphql.GraphQLResponse) ApiCategoryBehavior(com.amplifyframework.api.ApiCategoryBehavior) PaginatedResult(com.amplifyframework.api.graphql.PaginatedResult) QueryPredicate(com.amplifyframework.core.model.query.predicate.QueryPredicate) DataStoreException(com.amplifyframework.datastore.DataStoreException) GraphQLResponse(com.amplifyframework.api.graphql.GraphQLResponse) NoOpCancelable(com.amplifyframework.core.async.NoOpCancelable) Cancelable(com.amplifyframework.core.async.Cancelable) NoOpCancelable(com.amplifyframework.core.async.NoOpCancelable) ApiException(com.amplifyframework.api.ApiException)

Aggregations

NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AmplifyException (com.amplifyframework.AmplifyException)1 ApiCategoryBehavior (com.amplifyframework.api.ApiCategoryBehavior)1 ApiException (com.amplifyframework.api.ApiException)1 AuthModeStrategyType (com.amplifyframework.api.aws.AuthModeStrategyType)1 GraphQLBehavior (com.amplifyframework.api.graphql.GraphQLBehavior)1 GraphQLRequest (com.amplifyframework.api.graphql.GraphQLRequest)1 GraphQLResponse (com.amplifyframework.api.graphql.GraphQLResponse)1 PaginatedResult (com.amplifyframework.api.graphql.PaginatedResult)1 SubscriptionType (com.amplifyframework.api.graphql.SubscriptionType)1 Action (com.amplifyframework.core.Action)1 Amplify (com.amplifyframework.core.Amplify)1 Consumer (com.amplifyframework.core.Consumer)1 Cancelable (com.amplifyframework.core.async.Cancelable)1 NoOpCancelable (com.amplifyframework.core.async.NoOpCancelable)1 Model (com.amplifyframework.core.model.Model)1 ModelSchema (com.amplifyframework.core.model.ModelSchema)1 QueryPredicate (com.amplifyframework.core.model.query.predicate.QueryPredicate)1 QueryPredicates (com.amplifyframework.core.model.query.predicate.QueryPredicates)1