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

graphql.schema type with Subscriptions: null in causes errors when working with DataStore #928

Closed
dougie181 opened this issue Dec 2, 2020 · 8 comments
Labels
api Issues related to the API category datastore Issues related to the DataStore category feature-request Request a new feature

Comments

@dougie181
Copy link

dougie181 commented Dec 2, 2020

Describe the bug

I am getting the following subscription errors in my app:

`WebsocketDidReceiveMessage - {"id":"0E01CECF-6203-4A2A-8587-F1596834C125","type":"error","payload":{"errors":[{"message":"Validation error of type FieldUndefined: Field 'onCreateDeviceState' in type 'Subscription' is undefined @ 'onCreateDeviceState'"}]}}

ConnectionProviderError.jsonParse; identifier=0E01CECF-6203-4A2A-8587-F1596834C125; additionalInfo=Optional(["errors": AppSyncRealTimeClient.AppSyncJSONValue.array([AppSyncRealTimeClient.AppSyncJSONValue.object(["message": AppSyncRealTimeClient.AppSyncJSONValue.string("Validation error of type FieldUndefined: Field \'onCreateDeviceState\' in type \'Subscription\' is undefined @ \'onCreateDeviceState\'")])])])

[IncomingAsyncSubscriptionEventToAnyModelMapper] Received completion: failure(DataStoreError: Subscription item event failed with error
Caused by:
APIError: Subscription item event failed with error
Caused by:
GraphQLResponseError<MutationSync<AnyModel>>: GraphQL service returned a successful response containing errors: [Amplify.GraphQLError(message: "Validation error of type FieldUndefined: Field \'onCreateDeviceState\' in type \'Subscription\' is undefined @ \'onCreateDeviceState\'", locations: nil, path: nil, extensions: nil)]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages)

I have two types defined in a graphql.schema.

type Device @model @auth( rules: [ { allow: owner } ]  )
{
    id: ID!
    deviceID: String!
    createdAt: AWSDateTime!
    name: String
}

type DeviceState @model (subscriptions: null) @auth (
        rules: [
            { allow: private, provider: iam},
            { allow: private, provider: userPools, operations: [read] }
        ]  )
{
    id: ID!
    deviceId: String!
    payload: AWSJSON!
    timestamp: AWSTimestamp!
}

I am using datastore to sync Device data with the cloud and between devices. The DeviceState data is created from another source and am using API.query as a query method and I do not want to receive subscriptions for this data.

With the above schema, Datastore and subscriptions are not working at all.

If I remove the subscriptions: null from the DeviceState, the app works without any issues, although the app is then bombarded with subscription events from DeviceState, which I do not want.

To Reproduce
Steps to reproduce the behavior:

  1. Use the graphql.schema as shown above
  2. % amplify add auth
  3. % amplify add api
  4. % amplify update api [ensuring that the Enable DataStore for entire API ]
  5. % amplify push

Expected behavior
I would like to received subscriptions for Device data but not for DeviceState data.

Environment(please complete the following information):

  • Amplify Framework Version: [4.36.2]
  • Dependency Manager: [Cocoapods]
  • Swift Version : [5.0]

Device Information (please complete the following information):

  • Device: [Simulator]
  • iOS Version: [e.g. iOS 14]

Additional context
This may not be a bug, so any advice on how I can achieve this using a GraphQL API would be much appreciated.

@wooj2
Copy link
Contributor

wooj2 commented Dec 2, 2020

Hi @dougie181,

Thanks for reaching out to us and taking the time to explain your use case.

To better assist you, I will attempt to re-state your use case. Your application has a model called Device and a model called DeviceState. You want use DataStore to manage offline mutations and receive real time updates for the Device model, but not for DeviceState. For DeviceState you want to use the Amplify API category only. Is this correct?

@wooj2 wooj2 added datastore Issues related to the DataStore category enhancement pending-community-response Issue is pending response from the issue requestor api Issues related to the API category labels Dec 2, 2020
@dougie181
Copy link
Author

Hi @wooj2,
Yes, that is correct.

@wooj2 wooj2 added feature-request Request a new feature and removed enhancement pending-community-response Issue is pending response from the issue requestor labels Dec 3, 2020
@wooj2
Copy link
Contributor

wooj2 commented Dec 4, 2020

Hi @dougie181 ,

Thanks for getting back to us so quickly. I've talked with the team, and unfortunately, there is not an easy way to do this right now. We are considering this as a feature request and will keep you posted on any progress on this front.

@github-actions
Copy link
Contributor

This issue is stale because it has been open for 14 days with no activity. Please, provide an update or it will be automatically closed in 7 days.

@github-actions github-actions bot added closing soon This issue will be closed in 7 days unless further comments are made. and removed closing soon This issue will be closed in 7 days unless further comments are made. labels Jun 19, 2021
@felixolivares
Copy link

Are there any updates on this feature request ?

@lawmicha lawmicha added the p2 label Jun 8, 2022
@lawmicha
Copy link
Member

For what it's worth, since this issue has been opened, we have made some changes in DataStore to continue to operate against disabled subscriptions, the logic in the client library checks if the subscription request returns "Operation disabled". The way to set this up still isn't a fully supported use case that we have documented, but you can modify the subscription operation response mapping in AppSync to return "Operation disabled". Let us know if you are still looking for a solution to this and we can add an integration test that uses a subscriptions: null model and verify this is working and enforce we do not break this use case

Related code: https://github.com/aws-amplify/amplify-swift/blob/main/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/AWSIncomingEventReconciliationQueue.swift#L152-L154

@atierian atierian removed the p2 label Oct 16, 2023
@lawmicha
Copy link
Member

Since we haven't heard back on this issue in awhile now, feel free to open a new issue if something isn't working

Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues related to the API category datastore Issues related to the DataStore category feature-request Request a new feature
Projects
None yet
Development

No branches or pull requests

5 participants