Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataStore subscribes to non-existing mutations #1594

Open
1 task done
MorCohenAres opened this issue Dec 3, 2021 · 3 comments
Open
1 task done

DataStore subscribes to non-existing mutations #1594

MorCohenAres opened this issue Dec 3, 2021 · 3 comments
Labels
datastore DataStore category/plugins feature-request Request a new feature

Comments

@MorCohenAres
Copy link

MorCohenAres commented Dec 3, 2021

Before opening, please confirm:

Language and Async Model

Kotlin - Coroutines

Amplify Categories

DataStore

Gradle script dependencies

implementation 'com.amplifyframework:core-kotlin:0.12.1'
implementation 'com.amplifyframework:aws-api:1.28.1'
implementation 'com.amplifyframework:aws-datastore:1.28.1'
implementation 'com.amplifyframework:aws-auth-cognito:1.28.1'

Environment information

# Put output below this line
Build time:   2021-08-17 09:59:03 UTC
Revision:     a773786b58bb28710e3dc96c4d1a7063628952ad

Kotlin:       1.5.21
Groovy:       3.0.8
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          15.0.2 (Oracle Corporation 15.0.2+7-27)

Please include any relevant guides or documentation you're referencing

No response

Describe the bug

If we create a GraphQL schema with some @models, and disable some of the default mutations, DataStore category still tries to subscribe on the disabled mutations.
This behaviour leads to an error when performing any operation, because of the server rejecting the subscription.

Reproduction steps (if applicable)

  1. Create a schema similar to the one attached below
  2. Try using DataStore to query something.
  3. The attached error will be thrown

Code Snippet

Amplify.DataStore.query(AnyOfMyModels::class).collect {}

Log output

There is a `@model` called `PerformedBlockItem` in our schema. When I query, regardless of the queried model type, a similar error to this is thrown:
E/amplify:aws-datastore: Failure encountered while attempting to start API sync.
    GraphQLResponseException{message=Subscription error for PerformedBlockItem: [GraphQLResponse.Error{message='Validation error of type FieldUndefined: Field 'onCreatePerformedBlockItem' in type 'Subscription' is undefined @ 'onCreatePerformedBlockItem'', locations='null', path='null', extensions='null'}], errors=[GraphQLResponse.Error{message='Validation error of type FieldUndefined: Field 'onCreatePerformedBlockItem' in type 'Subscription' is undefined @ 'onCreatePerformedBlockItem'', locations='null', path='null', extensions='null'}], recoverySuggestion=See attached list of GraphQLResponse.Error objects.}
        at com.amplifyframework.datastore.appsync.AppSyncClient.lambda$subscription$2(AppSyncClient.java:321)
        at com.amplifyframework.datastore.appsync.AppSyncClient$$ExternalSyntheticLambda5.accept(Unknown Source:8)
        at com.amplifyframework.api.aws.SubscriptionEndpoint$Subscription.dispatchNextMessage(SubscriptionEndpoint.java:414)
        at com.amplifyframework.api.aws.SubscriptionEndpoint.notifySubscriptionData(SubscriptionEndpoint.java:248)
        at com.amplifyframework.api.aws.SubscriptionEndpoint.access$700(SubscriptionEndpoint.java:61)
        at com.amplifyframework.api.aws.SubscriptionEndpoint$AmplifyWebSocketListener.processJsonMessage(SubscriptionEndpoint.java:592)
        at com.amplifyframework.api.aws.SubscriptionEndpoint$AmplifyWebSocketListener.onMessage(SubscriptionEndpoint.java:498)

amplifyconfiguration.json

No response

GraphQL Schema

This is the schema before compilation:
type PerformedBlockItem @model(queries: null, mutations: null)
    id: ID!
    ... other things
}

This also happens when mutations is not null but contains only some of the mutations.
After compilation, the schema's Subscription part doesn't contain any subscription for our model.

Additional information and screenshots

As a workaround, I can let amplify generate all mutations (and all subscriptions), and block access to those I'm no interested in by permissions, but this is a really bad behavior I would like to avoid of course.

Code-wise:
I've seen in

synchronized void startSubscriptions() throws DataStoreException {
int subscriptionCount = modelProvider.modelNames().size() * SubscriptionType.values().length;
// Create a latch with the number of subscriptions are requesting. Each of these will be
// counted down when each subscription's onStarted event is called.
AbortableCountDownLatch<DataStoreException> latch = new AbortableCountDownLatch<>(subscriptionCount);
// Need to create a new buffer so we can properly handle retries and stop/start scenarios.
// Re-using the same buffer has some unexpected results due to the replay aspect of the subject.
buffer = ReplaySubject.create();
Set<Observable<SubscriptionEvent<? extends Model>>> subscriptions = new HashSet<>();
for (ModelSchema modelSchema : modelProvider.modelSchemas().values()) {
for (SubscriptionType subscriptionType : SubscriptionType.values()) {
subscriptions.add(subscriptionObservable(appSync, subscriptionType, latch, modelSchema));
}
}

It creates requests for all subscriptions regardless of which mutation really exists.
I also saw the same behavior in Amplify for JS. Maybe it's intentional for some reason.
Anyway It would be great if we can discuss this or find a solution.

@div5yesh div5yesh added the datastore DataStore category/plugins label Dec 10, 2021
@poojamat poojamat added the question General question label Jan 24, 2022
@poojamat
Copy link
Contributor

poojamat commented Apr 1, 2022

Did you disable the subscription as well?
What was your mechanism to disable mutation?

@MorCohenAres
Copy link
Author

Did you disable the subscription as well? What was your mechanism to disable mutation?

Thank you for your response!
The subscription is not generated in the first place if you disable the mutation.
I disabled the mutation by adding mutations: null into the @model definition in my schema (which is attached in the original question above).
Tried also subscriptions: null but Android seems to ignore those definitions when it tries to subscribe (see the attached code snippet).

@poojamat poojamat added bug Something isn't working and removed question General question labels May 2, 2022
@mikepschneider
Copy link
Contributor

Trying to understand the use case here, what is the point of disabling the default mutations? If there are no mutations how will you update the datastore?

@poojamat poojamat added p3 feature-request Request a new feature and removed p3 bug Something isn't working labels Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore DataStore category/plugins feature-request Request a new feature
Projects
None yet
Development

No branches or pull requests

4 participants