amplify-swift icon indicating copy to clipboard operation
amplify-swift copied to clipboard

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

Open dougie181 opened this issue 4 years ago • 5 comments

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.

dougie181 avatar Dec 02 '20 03:12 dougie181

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 avatar Dec 02 '20 21:12 wooj2

Hi @wooj2, Yes, that is correct.

dougie181 avatar Dec 02 '20 22:12 dougie181

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.

wooj2 avatar Dec 04 '20 01:12 wooj2

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[bot] avatar Jun 19 '21 00:06 github-actions[bot]

Are there any updates on this feature request ?

felixolivares avatar Nov 29 '21 06:11 felixolivares

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

lawmicha avatar Aug 10 '23 15:08 lawmicha

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

lawmicha avatar Jan 10 '24 13:01 lawmicha

⚠️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.

github-actions[bot] avatar Jan 10 '24 13:01 github-actions[bot]