amplify-swift: App Sync throwing "Not Authorized" for some fields

Describe the bug

When I run my app datastore attempts to sync my models data, but on 2 of my models some fields are returning as “Not Authorized to access member on type <Model>”. We are using the same infrastructure to web and iOS clients, and just on iOS I’m having this authentication issue when accessing models.

Here’s how I configure my Amplify:

 do {
            let apiPlugin = AWSAPIPlugin(modelRegistration: AmplifyModels())
            
            try Amplify.add(plugin: AWSDataStorePlugin(modelRegistration: AmplifyModels()))
            try Amplify.add(plugin: AWSCognitoAuthPlugin())
            try Amplify.add(plugin: AWSS3StoragePlugin())
            try Amplify.add(plugin: apiPlugin)
            try Amplify.configure()
            // I'm using a custom interceptor, bc without it I was receiving 401 when performing requests to the REST API 
            try apiPlugin.add(interceptor: CustomInterceptor(), for: AmplifyEndpoints.REST_API)
            print("Initialized Amplify")
        } catch {
            print("Could not initialize Amplify: \(error)")
        }
        
        struct CustomInterceptor: URLRequestInterceptor {
          func intercept(_ request: URLRequest) async throws -> URLRequest {
              var request = request
              request.setValue(try await getAccessToken(), forHTTPHeaderField: "Authorization")
              return request
          }
     }

Steps To Reproduce

Open the app with an authenticated session

Expected behavior

Be able to sync DataStore without errors

Amplify Framework Version

2.15.2

Amplify Categories

DataStore

Dependency manager

Swift PM

Swift version

5.8.1

CLI version

12.1.1

Xcode version

Xcode 14.3.1 (14E300b)

Relevant log output

<details>
<summary>Log Messages</summary>

-08-16 12:22:24.544276-0300 AppName[5835:2632035] [DataStoreRemoteSyncEngine] One or more errors occurred syncing models. See below for detailed error description.
2023-08-16 12:22:24.544458-0300 AppName[5835:2632035] [DataStoreRemoteSyncEngine] DataStoreError: An error occurred syncing Connection
Caused by:
GraphQLResponseError<PaginatedList<AnyModel>>: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(2.0), Amplify.JSONValue.string("member")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "data": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(0.0), Amplify.JSONValue.string("member")]), extensions: Optional(["errorType": Amplify.JSONValue.string("Unauthorized"), "data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(4.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(1.0), Amplify.JSONValue.string("member")]), extensions: Optional(["errorType": Amplify.JSONValue.string("Unauthorized"), "data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.
DataStoreError: An error occurred syncing Participant
Caused by:
DataStoreError: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access room on type Participant", locations: Optional([Amplify.GraphQLError.Location(line: 29, column: 7)]), path: Optional([Amplify.JSONValue.string("syncParticipants"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(0.0), Amplify.JSONValue.string("room")]), extensions: Optional(["errorType": Amplify.JSONValue.string("Unauthorized"), "data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null])), Amplify.GraphQLError(message: "Not Authorized to access room on type Participant", locations: Optional([Amplify.GraphQLError.Location(line: 29, column: 7)]), path: Optional([Amplify.JSONValue.string("syncParticipants"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(1.0), Amplify.JSONValue.string("room")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized"), "errorInfo": Amplify.JSONValue.null]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.

</details>

Is this a regression?

No

Regression additional context

No response

Platforms

iOS

OS Version

iOS 16.6

Device

iPhone 13

Specific to simulators

No

Additional context

Here’s the models involved in the bug

type User
	@model
	@auth(rules: [# { allow: private, operations: [sync, listen] } { allow: owner, operations: [read] }]) {
	id: ID
	owner: ID
	username: String
	email: String
	name: String
	givenName: String
	familyName: String
	picture: String
	searchTerm: String
	createdAt: AWSDateTime
	updatedAt: AWSDateTime
}

type Room @model @auth(rules: [{ allow: owner }]) {
	id: ID
	owner: ID
	userId: ID @index(name: "listRoomByUserId", queryField: "listRoomByUserId", sortKeyFields: ["createdAt"])
	teamId: ID @index(name: "listRoomByTeamId", queryField: "listRoomByTeamId", sortKeyFields: ["createdAt"])
	name: String
	isPrivate: Boolean
	roomKey: String
	isGroup: Boolean
	photoKey: String
	photoUrl: String
	searchTerm: String
	createdAt: AWSDateTime
	updatedAt: AWSDateTime
}

type Connection @model @auth(rules: [{ allow: owner }]) {
  id: ID
  owner: ID
  chatId: ID
    @index(
      name: "listConnectionByChatId"
      queryField: "listConnectionByChatId"
      sortKeyFields: ["createdAt"]
    )
  userId: ID
    @index(
      name: "listConnectionByUserId"
      queryField: "listConnectionByUserId"
      sortKeyFields: ["createdAt"]
    )
  memberId: ID
    @index(
      name: "listConnectionByMemberId"
      queryField: "listConnectionByMemberId"
      sortKeyFields: ["createdAt"]
    )
  user: User @hasOne(fields: ["userId"])
  member: User @hasOne(fields: ["memberId"])
  onlinePresence: OnlinePresence @hasOne(fields: ["memberId"])
  isSender: Boolean
  isReceiver: Boolean
  isAccepted: Boolean
  isDeclined: Boolean
  isBlocked: Boolean
  isMuted: Boolean
  isPinned: Boolean
  acceptedAt: AWSDateTime
  declinedAt: AWSDateTime
  blockedAt: AWSDateTime
  mutedAt: AWSDateTime
  pinnedAt: AWSDateTime
  createdAt: AWSDateTime
  updatedAt: AWSDateTime
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Hey folks, any updates on this issue?

I accidentally closed this issue while I was formatting these comment. Sorry about that. Here are the changes related to the Connection+Schema and Connection:

Connection+Schema diff
// swiftlint:disable all
import Amplify
import Foundation

extension Connection {
  // MARK: - CodingKeys 
   public enum CodingKeys: String, ModelKey {
    case id
    case owner
    case chatId
    case userId
    case memberId
    case user
    case member
    case onlinePresence
    case isSender
    case isReceiver
    case isAccepted
    case isDeclined
    case isBlocked
    case isMuted
    case isPinned
    case acceptedAt
    case declinedAt
    case blockedAt
    case mutedAt
    case pinnedAt
    case createdAt
    case updatedAt
  }
  
  public static let keys = CodingKeys.self
  //  MARK: - ModelSchema 
  
  public static let schema = defineSchema { model in
    let connection = Connection.keys
    
    model.authRules = [
      rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", provider: .userPools, operations: [.create, .update, .delete, .read])
    ]
-   model.pluralName = "Connections"
+   model.listPluralName = "Connections"
+   model.syncPluralName = "Connections"
    
    model.attributes(
      .index(fields: ["chatId", "createdAt"], name: "listConnectionByChatId"),
      .index(fields: ["userId", "createdAt"], name: "listConnectionByUserId"),
      .index(fields: ["memberId", "createdAt"], name: "listConnectionByMemberId")
    )
    
    model.fields(
      .id(),
      .field(connection.owner, is: .optional, ofType: .string),
      .field(connection.chatId, is: .optional, ofType: .string),
      .field(connection.userId, is: .optional, ofType: .string),
      .field(connection.memberId, is: .optional, ofType: .string),
      .hasOne(connection.user, is: .optional, ofType: User.self, associatedWith: User.keys.id, targetName: "userId"),
      .hasOne(connection.member, is: .optional, ofType: User.self, associatedWith: User.keys.id, targetName: "memberId"),
      .hasOne(connection.onlinePresence, is: .optional, ofType: OnlinePresence.self, associatedWith: OnlinePresence.keys.id, targetName: "memberId"),
      .field(connection.isSender, is: .optional, ofType: .bool),
      .field(connection.isReceiver, is: .optional, ofType: .bool),
      .field(connection.isAccepted, is: .optional, ofType: .bool),
      .field(connection.isDeclined, is: .optional, ofType: .bool),
      .field(connection.isBlocked, is: .optional, ofType: .bool),
      .field(connection.isMuted, is: .optional, ofType: .bool),
      .field(connection.isPinned, is: .optional, ofType: .bool),
      .field(connection.acceptedAt, is: .optional, ofType: .dateTime),
      .field(connection.declinedAt, is: .optional, ofType: .dateTime),
      .field(connection.blockedAt, is: .optional, ofType: .dateTime),
      .field(connection.mutedAt, is: .optional, ofType: .dateTime),
      .field(connection.pinnedAt, is: .optional, ofType: .dateTime),
      .field(connection.createdAt, is: .optional, ofType: .dateTime),
      .field(connection.updatedAt, is: .optional, ofType: .dateTime)
    )
    }
    public class Path: ModelPath<Connection> { }
    
    public static var rootPath: PropertyContainerPath? { Path() }
}
+extension ModelPath where ModelType == Connection {
+  public var id: FieldPath<String>   {
+      string("id") 
+    }
+  public var owner: FieldPath<String>   {
+      string("owner") 
+    }
+  public var chatId: FieldPath<String>   {
+      string("chatId") 
+    }
+  public var userId: FieldPath<String>   {
+      string("userId") 
+    }
+  public var memberId: FieldPath<String>   {
+      string("memberId") 
+    }
+  public var user: ModelPath<User>   {
+      User.Path(name: "user", parent: self) 
+    }
+  public var member: ModelPath<User>   {
+      User.Path(name: "member", parent: self) 
+    }
+  public var onlinePresence: ModelPath<OnlinePresence>   {
+      OnlinePresence.Path(name: "onlinePresence", parent: self) 
+    }
+  public var isSender: FieldPath<Bool>   {
+      bool("isSender") 
+    }
+  public var isReceiver: FieldPath<Bool>   {
+      bool("isReceiver") 
+    }
+  public var isAccepted: FieldPath<Bool>   {
+      bool("isAccepted") 
+    }
+  public var isDeclined: FieldPath<Bool>   {
+      bool("isDeclined") 
+    }
+  public var isBlocked: FieldPath<Bool>   {
+      bool("isBlocked") 
+    }
+  public var isMuted: FieldPath<Bool>   {
+      bool("isMuted") 
+    }
+  public var isPinned: FieldPath<Bool>   {
+      bool("isPinned") 
+    }
+  public var acceptedAt: FieldPath<Temporal.DateTime>   {
+      datetime("acceptedAt") 
+    }
+  public var declinedAt: FieldPath<Temporal.DateTime>   {
+      datetime("declinedAt") 
+    }
+  public var blockedAt: FieldPath<Temporal.DateTime>   {
+      datetime("blockedAt") 
+    }
+  public var mutedAt: FieldPath<Temporal.DateTime>   {
+      datetime("mutedAt") 
+    }
+  public var pinnedAt: FieldPath<Temporal.DateTime>   {
+      datetime("pinnedAt") 
+    }
+  public var createdAt: FieldPath<Temporal.DateTime>   {
+      datetime("createdAt") 
+    }
+  public var updatedAt: FieldPath<Temporal.DateTime>   {
+      datetime("updatedAt") 
+    }
+}
Connection diff
// swiftlint:disable all
import Amplify
import Foundation

public struct Connection: Model {
  public let id: String
  public var owner: String?
  public var chatId: String?
  public var userId: String?
  public var memberId: String?
+  internal var _user: LazyReference<User>
-  public var user: User?
+  public var user: User?   {
+      get async throws { 
+        try await _user.get()
+      } 
+    }
+  internal var _member: LazyReference<User>
-  public var member: User?
+  public var member: User?   {
+      get async throws { 
+        try await _member.get()
+      } 
+    }
+  internal var _onlinePresence: LazyReference<OnlinePresence>
-  public var onlinePresence: OnlinePresence?
+  public var onlinePresence: OnlinePresence?   {
+      get async throws { 
+        try await _onlinePresence.get()
+      } 
+    }
  public var isSender: Bool?
  public var isReceiver: Bool?
  public var isAccepted: Bool?
  public var isDeclined: Bool?
  public var isBlocked: Bool?
  public var isMuted: Bool?
  public var isPinned: Bool?
  public var acceptedAt: Temporal.DateTime?
  public var declinedAt: Temporal.DateTime?
  public var blockedAt: Temporal.DateTime?
  public var mutedAt: Temporal.DateTime?
  public var pinnedAt: Temporal.DateTime?
  public var createdAt: Temporal.DateTime?
  public var updatedAt: Temporal.DateTime?
  
  public init(id: String = UUID().uuidString,
      owner: String? = nil,
      chatId: String? = nil,
      userId: String? = nil,
      memberId: String? = nil,
      user: User? = nil,
      member: User? = nil,
      onlinePresence: OnlinePresence? = nil,
      isSender: Bool? = nil,
      isReceiver: Bool? = nil,
      isAccepted: Bool? = nil,
      isDeclined: Bool? = nil,
      isBlocked: Bool? = nil,
      isMuted: Bool? = nil,
      isPinned: Bool? = nil,
      acceptedAt: Temporal.DateTime? = nil,
      declinedAt: Temporal.DateTime? = nil,
      blockedAt: Temporal.DateTime? = nil,
      mutedAt: Temporal.DateTime? = nil,
      pinnedAt: Temporal.DateTime? = nil,
      createdAt: Temporal.DateTime? = nil,
      updatedAt: Temporal.DateTime? = nil) {
      self.id = id
      self.owner = owner
      self.chatId = chatId
      self.userId = userId
      self.memberId = memberId
-      self.user = user
-      self.member = member
-      self.onlinePresence = onlinePresence
+      self._user = LazyReference(user)
+      self._member = LazyReference(member)
+      self._onlinePresence = LazyReference(onlinePresence)
      self.isSender = isSender
      self.isReceiver = isReceiver
      self.isAccepted = isAccepted
      self.isDeclined = isDeclined
      self.isBlocked = isBlocked
      self.isMuted = isMuted
      self.isPinned = isPinned
      self.acceptedAt = acceptedAt
      self.declinedAt = declinedAt
      self.blockedAt = blockedAt
      self.mutedAt = mutedAt
      self.pinnedAt = pinnedAt
      self.createdAt = createdAt
      self.updatedAt = updatedAt
  }
+  public mutating func setUser(_ user: User? = nil) {
+    self._user = LazyReference(user)
+  }
+  public mutating func setMember(_ member: User? = nil) {
+    self._member = LazyReference(member)
+  }
+  public mutating func setOnlinePresence(_ onlinePresence: OnlinePresence? = nil) {
+    self._onlinePresence = LazyReference(onlinePresence)
+  }
+  public init(from decoder: Decoder) throws {
+      let values = try decoder.container(keyedBy: CodingKeys.self)
+      id = try values.decode(String.self, forKey: .id)
+      owner = try? values.decode(String?.self, forKey: .owner)
+      chatId = try? values.decode(String?.self, forKey: .chatId)
+      userId = try? values.decode(String?.self, forKey: .userId)
+      memberId = try? values.decode(String?.self, forKey: .memberId)
+      _user = try values.decodeIfPresent(LazyReference<User>.self, forKey: .user) ?? LazyReference(identifiers: nil)
+      _member = try values.decodeIfPresent(LazyReference<User>.self, forKey: .member) ?? LazyReference(identifiers: nil)
+      _onlinePresence = try values.decodeIfPresent(LazyReference<OnlinePresence>.self, forKey: .onlinePresence) ?? LazyReference(identifiers: nil)
+      isSender = try? values.decode(Bool?.self, forKey: .isSender)
+      isReceiver = try? values.decode(Bool?.self, forKey: .isReceiver)
+      isAccepted = try? values.decode(Bool?.self, forKey: .isAccepted)
+      isDeclined = try? values.decode(Bool?.self, forKey: .isDeclined)
+      isBlocked = try? values.decode(Bool?.self, forKey: .isBlocked)
+      isMuted = try? values.decode(Bool?.self, forKey: .isMuted)
+      isPinned = try? values.decode(Bool?.self, forKey: .isPinned)
+      acceptedAt = try? values.decode(Temporal.DateTime?.self, forKey: .acceptedAt)
+      declinedAt = try? values.decode(Temporal.DateTime?.self, forKey: .declinedAt)
+      blockedAt = try? values.decode(Temporal.DateTime?.self, forKey: .blockedAt)
+      mutedAt = try? values.decode(Temporal.DateTime?.self, forKey: .mutedAt)
+      pinnedAt = try? values.decode(Temporal.DateTime?.self, forKey: .pinnedAt)
+      createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt)
+      updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt)
+  }
+  public func encode(to encoder: Encoder) throws {
+      var container = encoder.container(keyedBy: CodingKeys.self)
+      try container.encode(id, forKey: .id)
+      try container.encode(owner, forKey: .owner)
+      try container.encode(chatId, forKey: .chatId)
+      try container.encode(userId, forKey: .userId)
+      try container.encode(memberId, forKey: .memberId)
+      try container.encode(_user, forKey: .user)
+      try container.encode(_member, forKey: .member)
+      try container.encode(_onlinePresence, forKey: .onlinePresence)
+      try container.encode(isSender, forKey: .isSender)
+      try container.encode(isReceiver, forKey: .isReceiver)
+      try container.encode(isAccepted, forKey: .isAccepted)
+      try container.encode(isDeclined, forKey: .isDeclined)
+      try container.encode(isBlocked, forKey: .isBlocked)
+      try container.encode(isMuted, forKey: .isMuted)
+      try container.encode(isPinned, forKey: .isPinned)
+      try container.encode(acceptedAt, forKey: .acceptedAt)
+      try container.encode(declinedAt, forKey: .declinedAt)
+      try container.encode(blockedAt, forKey: .blockedAt)
+      try container.encode(mutedAt, forKey: .mutedAt)
+      try container.encode(pinnedAt, forKey: .pinnedAt)
+      try container.encode(createdAt, forKey: .createdAt)
+      try container.encode(updatedAt, forKey: .updatedAt)
+  }
+}

Hi @lawmicha, I’ve added the feature flag to cli.json, and regenerated my models, but DataStore still having errors when it’s trying to sync with Connections and Participants.

DataStore Logs
2023-09-06 12:52:51.115398-0300 MyApp[16638:8436428] [DataStoreInitialSyncOperation] Beginning sync for Message
2023-09-06 12:52:51.854680-0300 MyApp[16638:8436428] [DataStoreInitialSyncOperation] Beginning sync for MessageEvent
2023-09-06 12:52:52.251079-0300 MyApp[16638:8436428] [DataStoreInitialSyncOperation] Beginning sync for MessageReaction
2023-09-06 12:52:52.968563-0300 MyApp[16638:8436433] [DataStoreInitialSyncOperation] Beginning sync for MessageStat
2023-09-06 12:52:53.266887-0300 MyApp[16638:8436433] [DataStoreInitialSyncOperation] Beginning sync for OnlinePresence
2023-09-06 12:52:53.993847-0300 MyApp[16638:8436459] [DataStoreInitialSyncOperation] Beginning sync for Participant
2023-09-06 12:52:54.818924-0300 MyApp[16638:8436426] [DataStoreInitialSyncOperation] Beginning sync for Room
2023-09-06 12:52:55.632576-0300 MyApp[16638:8436460] [DataStoreInitialSyncOperation] Beginning sync for RoomSetting
2023-09-06 12:52:56.553330-0300 MyApp[16638:8436433] [DataStoreInitialSyncOperation] Beginning sync for User
2023-09-06 12:52:57.290107-0300 MyApp[16638:8436433] [DataStoreRemoteSyncEngine] One or more errors occurred syncing models. See below for detailed error description.
2023-09-06 12:52:57.290266-0300 MyApp[16638:8436433] [DataStoreRemoteSyncEngine] DataStoreError: An error occurred syncing Connection
Caused by:
DataStoreError: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(1.0), Amplify.JSONValue.string("member")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "data": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(2.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(3.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.
Caused by:
GraphQLResponseError<PaginatedList<AnyModel>>: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(1.0), Amplify.JSONValue.string("member")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "data": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(2.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(3.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.
DataStoreError: An error occurred syncing Participant
Caused by:
DataStoreError: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access room on type Participant", locations: Optional([Amplify.GraphQLError.Location(line: 22, column: 7)]), path: Optional([Amplify.JSONValue.string("syncParticipants"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(0.0), Amplify.JSONValue.string("room")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized"), "data": Amplify.JSONValue.null]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.
Caused by:
GraphQLResponseError<PaginatedList<AnyModel>>: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access room on type Participant", locations: Optional([Amplify.GraphQLError.Location(line: 22, column: 7)]), path: Optional([Amplify.JSONValue.string("syncParticipants"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(0.0), Amplify.JSONValue.string("room")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized"), "data": Amplify.JSONValue.null]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.

2023-09-06 12:52:57.299664-0300 MyApp[16638:8436496] [DataStoreReadyEventEmitter] Failed to emit ready event, error: DataStoreError: One or more errors occurred syncing models. See below for detailed error description.
Recovery suggestion: DataStoreError: An error occurred syncing Connection
Caused by:
DataStoreError: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(1.0), Amplify.JSONValue.string("member")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "data": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(2.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(3.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.
Caused by:
GraphQLResponseError<PaginatedList<AnyModel>>: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(1.0), Amplify.JSONValue.string("member")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "data": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(2.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(3.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.
DataStoreError: An error occurred syncing Participant
Caused by:
DataStoreError: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access room on type Participant", locations: Optional([Amplify.GraphQLError.Location(line: 22, column: 7)]), path: Optional([Amplify.JSONValue.string("syncParticipants"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(0.0), Amplify.JSONValue.string("room")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized"), "data": Amplify.JSONValue.null]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.
Caused by:
GraphQLResponseError<PaginatedList<AnyModel>>: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access room on type Participant", locations: Optional([Amplify.GraphQLError.Location(line: 22, column: 7)]), path: Optional([Amplify.JSONValue.string("syncParticipants"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(0.0), Amplify.JSONValue.string("room")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized"), "data": Amplify.JSONValue.null]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.
Caused by:
DataStoreError: One or more errors occurred syncing models. See below for detailed error description.
Recovery suggestion: DataStoreError: An error occurred syncing Connection
Caused by:
DataStoreError: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(1.0), Amplify.JSONValue.string("member")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "data": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(2.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(3.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.
Caused by:
GraphQLResponseError<PaginatedList<AnyModel>>: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(1.0), Amplify.JSONValue.string("member")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "data": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(2.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")])), Amplify.GraphQLError(message: "Not Authorized to access member on type Connection", locations: Optional([Amplify.GraphQLError.Location(line: 23, column: 7)]), path: Optional([Amplify.JSONValue.string("syncConnections"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(3.0), Amplify.JSONValue.string("member")]), extensions: Optional(["data": Amplify.JSONValue.null, "errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized")]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.
DataStoreError: An error occurred syncing Participant
Caused by:
DataStoreError: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access room on type Participant", locations: Optional([Amplify.GraphQLError.Location(line: 22, column: 7)]), path: Optional([Amplify.JSONValue.string("syncParticipants"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(0.0), Amplify.JSONValue.string("room")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized"), "data": Amplify.JSONValue.null]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.
Caused by:
GraphQLResponseError<PaginatedList<AnyModel>>: GraphQL service returned a partially-successful response containing errors: [Amplify.GraphQLError(message: "Not Authorized to access room on type Participant", locations: Optional([Amplify.GraphQLError.Location(line: 22, column: 7)]), path: Optional([Amplify.JSONValue.string("syncParticipants"), Amplify.JSONValue.string("items"), Amplify.JSONValue.number(0.0), Amplify.JSONValue.string("room")]), extensions: Optional(["errorInfo": Amplify.JSONValue.null, "errorType": Amplify.JSONValue.string("Unauthorized"), "data": Amplify.JSONValue.null]))]
Recovery suggestion: The list of `GraphQLError` contains service-specific messages.

2023-09-06 12:52:57.302293-0300 MyApp[16638:8436496] [DataStoreStorageEngine] Stopping DataStore successful.

Hey, are there any updates on your investigation, and what’s the average time it usually takes to receive updates?

After further investigation, I noticed the web project is performing a query with fewer fields than the iOS does:

Query from web project
query operation($limit: Int, $nextToken: String, $lastSync: AWSTimestamp, $filter: ModelConnectionFilterInput) {
syncConnections(
limit: $limit
nextToken: $nextToken
lastSync: $lastSync
filter: $filter
) {
items {
id
owner
chatId
userId
memberId
isSender
isReceiver
isAccepted
isDeclined
isBlocked
isMuted
isPinned
acceptedAt
declinedAt
blockedAt
mutedAt
pinnedAt
createdAt
updatedAt
_version
_lastChangedAt
_deleted
}
nextToken
startedAt
}}
Query from iOS project
query SyncConnections($limit: Int) {
syncConnections(limit: $limit) {
items {
id
acceptedAt
blockedAt
chatId
createdAt
declinedAt
isAccepted
isBlocked
isDeclined
isMuted
isPinned
isReceiver
isSender
memberId
mutedAt
owner
pinnedAt
updatedAt
userId
member {
id
createdAt
email
familyName
givenName
name
owner
picture
searchTerm
updatedAt
username
typename
_version
_deleted
_lastChangedAt
}
onlinePresence {
id
createdAt
lastSeenAt
owner
status
updatedAt
typename
_version
_deleted
_lastChangedAt
}
user {
id
createdAt
email
familyName
givenName
name
owner
picture
searchTerm
updatedAt
username
typename
_version
_deleted
_lastChangedAt
}
typename
_version
_deleted
_lastChangedAt
}
nextToken
startedAt
}}

But the same query that’s defined at myProjectWeb/amplify/backend/function/myProjectLambda/src/gql shows the same structure as the iOS query.

Query from lambda folder
exports.syncConnections = /* GraphQL */ `
	query SyncConnections($filter: ModelConnectionFilterInput, $limit: Int, $nextToken: String, $lastSync: AWSTimestamp) {
		syncConnections(filter: $filter, limit: $limit, nextToken: $nextToken, lastSync: $lastSync) {
			items {
				id
				owner
				chatId
				userId
				memberId
				user {
					id
					owner
					username
					email
					name
					givenName
					familyName
					picture
					searchTerm
					createdAt
					updatedAt
					_version
					_deleted
					_lastChangedAt
				}
				member {
					id
					owner
					username
					email
					name
					givenName
					familyName
					picture
					searchTerm
					createdAt
					updatedAt
					_version
					_deleted
					_lastChangedAt
				}
				onlinePresence {
					id
					owner
					status
					lastSeenAt
					createdAt
					updatedAt
					_version
					_deleted
					_lastChangedAt
				}
				isSender
				isReceiver
				isAccepted
				isDeclined
				isBlocked
				isMuted
				isPinned
				acceptedAt
				declinedAt
				blockedAt
				mutedAt
				pinnedAt
				createdAt
				updatedAt
				_version
				_deleted
				_lastChangedAt
			}
			nextToken
			startedAt
		}
	}
`;

Testing both queries on AppSync console with an authenticated user, I managed to get the data using the web query, while the iOS query returned unauthorized errors as the DataStore sync errors I sent before.

So I believe that’s why I don’t get the iOS errors on web, but the question I raise is: There’s a way to modify the query structure on iOS? Or maybe modify it on backend?

Thanks for opening this issue.

The team will investigate and get back to you as soon as we have more information.