From f5717444a696f0c64011f21c47334181950b62c4 Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Tue, 27 Oct 2020 08:49:50 -0700 Subject: [PATCH 01/14] fixed failed syncEventEmitterTests --- .../InitialSync/SyncEventEmitterTests.swift | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Sync/InitialSync/SyncEventEmitterTests.swift b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Sync/InitialSync/SyncEventEmitterTests.swift index 78fe43dcdd..3cd69f6fb0 100644 --- a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Sync/InitialSync/SyncEventEmitterTests.swift +++ b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Sync/InitialSync/SyncEventEmitterTests.swift @@ -111,10 +111,10 @@ class SyncEventEmitterTests: XCTestCase { var modelSyncedEventPayloads = [ModelSyncedEvent]() let expectedModelSyncedEventPayloads: [ModelSyncedEvent] - = [ModelSyncedEvent(modelName: "Post", + = [ModelSyncedEvent(modelName: "Comment", isFullSync: true, isDeltaSync: false, added: 0, updated: 0, deleted: 0), - ModelSyncedEvent(modelName: "Comment", + ModelSyncedEvent(modelName: "Post", isFullSync: true, isDeltaSync: false, added: 0, updated: 0, deleted: 0)] let listener = Amplify.Hub.publisher(for: .dataStore).sink { payload in @@ -126,6 +126,9 @@ class SyncEventEmitterTests: XCTestCase { } modelSyncedEventPayloads.append(modelSyncedEventPayload) if modelSyncedEventPayloads.count == 2 { + modelSyncedEventPayloads.sort { + $0.modelName < $1.modelName + } XCTAssertEqual(modelSyncedEventPayloads[0], expectedModelSyncedEventPayloads[0]) XCTAssertEqual(modelSyncedEventPayloads[1], expectedModelSyncedEventPayloads[1]) modelSyncedReceived.fulfill() @@ -200,12 +203,12 @@ class SyncEventEmitterTests: XCTestCase { let commentMutationEvent = try MutationEvent(untypedModel: testComment, mutationType: .delete) let expectedModelSyncedEventPayloads: [ModelSyncedEvent] - = [ModelSyncedEvent(modelName: "Post", + = [ModelSyncedEvent(modelName: "Comment", isFullSync: true, isDeltaSync: false, - added: 1, updated: 0, deleted: 0), - ModelSyncedEvent(modelName: "Comment", + added: 0, updated: 0, deleted: 1), + ModelSyncedEvent(modelName: "Post", isFullSync: true, isDeltaSync: false, - added: 0, updated: 0, deleted: 1)] + added: 1, updated: 0, deleted: 0)] var modelSyncedEventPayloads = [ModelSyncedEvent]() let listener = Amplify.Hub.publisher(for: .dataStore).sink { payload in switch payload.eventName { @@ -217,6 +220,9 @@ class SyncEventEmitterTests: XCTestCase { modelSyncedEventPayloads.append(modelSyncedEventPayload) if modelSyncedEventPayloads.count == 2 { + modelSyncedEventPayloads.sort { + $0.modelName < $1.modelName + } XCTAssertTrue(modelSyncedEventPayloads[0] == expectedModelSyncedEventPayloads[0]) XCTAssertTrue(modelSyncedEventPayloads[1] == expectedModelSyncedEventPayloads[1]) modelSyncedReceived.fulfill() From 4c8b6a27f483a34e3202d70535900577649282da Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Tue, 10 Nov 2020 19:27:56 -0800 Subject: [PATCH 02/14] PR of correcting columnname for connection schema --- .../Schema/ModelSchema+Definition.swift | 10 +++ .../Categories/DataStore/Query/ModelKey.swift | 36 ++++++---- .../Subscribe/MutationEvent+Schema.swift | 4 ++ .../Model/AnyModel/AnyModel.swift | 4 ++ .../Model/Support/Model+GraphQL.swift | 4 +- .../ModelSync/ModelSyncMetadata+Schema.swift | 4 ++ .../MutationSyncMetadata+Schema.swift | 4 ++ .../Models/DynamicModel.swift | 4 ++ .../Models/ExampleWithEveryType+Schema.swift | 4 ++ AmplifyPlugins/DataStore/Podfile.lock | 2 +- AmplifyTestCommon/Models/Article+Schema.swift | 4 ++ .../Models/Associations/Author+Schema.swift | 4 ++ .../Models/Associations/Book+Schema.swift | 4 ++ .../Associations/BookAuthor+Schema.swift | 4 ++ .../Associations/UserAccount+Schema.swift | 4 ++ .../Associations/UserProfile+Schema.swift | 4 ++ AmplifyTestCommon/Models/Comment+Schema.swift | 40 ++++++----- .../Models/Deprecated/DeprecatedTodo.swift | 68 ++++++++++--------- AmplifyTestCommon/Models/MockModels.swift | 8 +++ .../Models/NonModel/DynamicEmbedded.swift | 5 ++ .../Models/NonModel/DynamicModel.swift | 4 ++ .../Models/NonModel/Todo+Schema.swift | 48 +++++++------ .../OGCScenarioBMGroupPost+Schema.swift | 54 ++++++++------- .../Models/OGCScenarioBPost+Schema.swift | 54 ++++++++------- AmplifyTestCommon/Models/Post+Schema.swift | 60 ++++++++-------- .../Models/ScenarioATest6Post+Schema.swift | 38 ++++++----- AmplifyTestCommon/Models/User+Schema.swift | 40 ++++++----- .../Models/UserFollowers+Schema.swift | 36 +++++----- .../Models/UserFollowing+Schema.swift | 36 +++++----- Podfile.lock | 2 +- 30 files changed, 360 insertions(+), 233 deletions(-) diff --git a/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Definition.swift b/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Definition.swift index 80d285edc3..1daae1d4eb 100644 --- a/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Definition.swift +++ b/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Definition.swift @@ -121,6 +121,16 @@ public struct ModelSchemaDefinition { public mutating func fields(_ fields: ModelFieldDefinition...) { fields.forEach { definition in let field = definition.modelField +// switch field.association { +// case .belongsTo(_, let targetName): +// guard let targetName = targetName else { +// return +// } +// self.fields[targetName] = field +// return +// default: +// break +// } self.fields[field.name] = field } } diff --git a/Amplify/Categories/DataStore/Query/ModelKey.swift b/Amplify/Categories/DataStore/Query/ModelKey.swift index add03d5d3b..fea75527cb 100644 --- a/Amplify/Categories/DataStore/Query/ModelKey.swift +++ b/Amplify/Categories/DataStore/Query/ModelKey.swift @@ -32,24 +32,35 @@ import Foundation /// post.content != nil /// }) /// ``` -public protocol ModelKey: CodingKey, CaseIterable, QueryFieldOperation {} +public protocol ModelKey: CodingKey, CaseIterable, QueryFieldOperation { + var modelType: Model.Type { get } +} extension CodingKey where Self: ModelKey { + var columnName: String { + switch modelType.schema.field(withName: stringValue)?.association { + case .belongsTo(_, let targetName): + return targetName! + default: + return stringValue + } + } + // MARK: - beginsWith public func beginsWith(_ value: String) -> QueryPredicateOperation { - return field(stringValue).beginsWith(value) + return field(columnName).beginsWith(value) } // MARK: - between public func between(start: Persistable, end: Persistable) -> QueryPredicateOperation { - return field(stringValue).between(start: start, end: end) + return field(columnName).between(start: start, end: end) } // MARK: - contains public func contains(_ value: String) -> QueryPredicateOperation { - return field(stringValue).contains(value) + return field(columnName).contains(value) } public static func ~= (key: Self, value: String) -> QueryPredicateOperation { @@ -59,14 +70,15 @@ extension CodingKey where Self: ModelKey { // MARK: - eq public func eq(_ value: Persistable?) -> QueryPredicateOperation { - return field(stringValue).eq(value) + return field(columnName).eq(value) } public func eq(_ value: EnumPersistable) -> QueryPredicateOperation { - return field(stringValue).eq(value) + return field(columnName).eq(value) } public static func == (key: Self, value: Persistable?) -> QueryPredicateOperation { + return key.eq(value) } @@ -77,7 +89,7 @@ extension CodingKey where Self: ModelKey { // MARK: - ge public func ge(_ value: Persistable) -> QueryPredicateOperation { - return field(stringValue).ge(value) + return field(columnName).ge(value) } public static func >= (key: Self, value: Persistable) -> QueryPredicateOperation { @@ -87,7 +99,7 @@ extension CodingKey where Self: ModelKey { // MARK: - gt public func gt(_ value: Persistable) -> QueryPredicateOperation { - return field(stringValue).gt(value) + return field(columnName).gt(value) } public static func > (key: Self, value: Persistable) -> QueryPredicateOperation { @@ -97,7 +109,7 @@ extension CodingKey where Self: ModelKey { // MARK: - le public func le(_ value: Persistable) -> QueryPredicateOperation { - return field(stringValue).le(value) + return field(columnName).le(value) } public static func <= (key: Self, value: Persistable) -> QueryPredicateOperation { @@ -107,7 +119,7 @@ extension CodingKey where Self: ModelKey { // MARK: - lt public func lt(_ value: Persistable) -> QueryPredicateOperation { - return field(stringValue).lt(value) + return field(columnName).lt(value) } public static func < (key: Self, value: Persistable) -> QueryPredicateOperation { @@ -117,11 +129,11 @@ extension CodingKey where Self: ModelKey { // MARK: - ne public func ne(_ value: Persistable?) -> QueryPredicateOperation { - return field(stringValue).ne(value) + return field(columnName).ne(value) } public func ne(_ value: EnumPersistable) -> QueryPredicateOperation { - return field(stringValue).ne(value) + return field(columnName).ne(value) } public static func != (key: Self, value: Persistable?) -> QueryPredicateOperation { diff --git a/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift b/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift index 6091800a9a..590c32a812 100644 --- a/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift +++ b/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift @@ -18,6 +18,10 @@ extension MutationEvent { case version case inProcess case graphQLFilterJSON + + public var modelType: Model.Type { + return MutationEvent.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift index 1e2ea11703..caa5735f4b 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift @@ -31,6 +31,10 @@ extension AnyModel { case id case instance case modelName + + public var modelType: Model.Type { + return AnyModel.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/Model+GraphQL.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/Model+GraphQL.swift index 866210d89a..f4ba3ee0f9 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/Model+GraphQL.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/Model+GraphQL.swift @@ -28,13 +28,13 @@ extension Model { let name = field.graphQLName let fieldOptionalValue: Any?? - + if let jsonModel = self as? JSONValueHolder { fieldOptionalValue = jsonModel.jsonValue(for: field.name, modelSchema: modelSchema) ?? nil } else { fieldOptionalValue = self[field.name] ?? nil } - + // Since the returned value is Any?? we need to do the following: // - `guard` to make sure the field name exists on the model // - `guard` to ensure the returned value isn't nil diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift b/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift index 8cddb6cb4c..a1cd5962c1 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift @@ -15,6 +15,10 @@ extension ModelSyncMetadata { public enum CodingKeys: String, ModelKey { case id case lastSync + + public var modelType: Model.Type { + return ModelSyncMetadata.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift b/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift index 3355ff3f8c..27567d46a8 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift @@ -17,6 +17,10 @@ extension MutationSyncMetadata { case deleted case lastChangedAt case version + + public var modelType: Model.Type { + return MutationSyncMetadata.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift index f68e6469a6..e519fa4967 100644 --- a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift +++ b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift @@ -82,6 +82,10 @@ extension DynamicModel { public enum CodingKeys: String, ModelKey { case id case values + + public var modelType: Model.Type { + return DynamicModel.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift index d328f64315..3552f0f3a8 100644 --- a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift +++ b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift @@ -22,6 +22,10 @@ extension ExampleWithEveryType { case enumField case nonModelField case arrayOfStringsField + + public var modelType: Model.Type { + return ExampleWithEveryType.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/DataStore/Podfile.lock b/AmplifyPlugins/DataStore/Podfile.lock index 9a25490d54..a113401710 100644 --- a/AmplifyPlugins/DataStore/Podfile.lock +++ b/AmplifyPlugins/DataStore/Podfile.lock @@ -122,4 +122,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 04860e414d616b67d24ed3346a60700f427764b9 -COCOAPODS: 1.9.3 +COCOAPODS: 1.10.0 diff --git a/AmplifyTestCommon/Models/Article+Schema.swift b/AmplifyTestCommon/Models/Article+Schema.swift index 93e4802b81..7c5e3c1eba 100644 --- a/AmplifyTestCommon/Models/Article+Schema.swift +++ b/AmplifyTestCommon/Models/Article+Schema.swift @@ -17,6 +17,10 @@ extension Article { case createdAt case owner case authorNotes + + public var modelType: Model.Type { + return Article.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Associations/Author+Schema.swift b/AmplifyTestCommon/Models/Associations/Author+Schema.swift index 6a525a8315..627955c90f 100644 --- a/AmplifyTestCommon/Models/Associations/Author+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/Author+Schema.swift @@ -14,6 +14,10 @@ extension Author { public enum CodingKeys: String, ModelKey { case id case books + + public var modelType: Model.Type { + return Author.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Associations/Book+Schema.swift b/AmplifyTestCommon/Models/Associations/Book+Schema.swift index 4b7f852b1f..536408382d 100644 --- a/AmplifyTestCommon/Models/Associations/Book+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/Book+Schema.swift @@ -14,6 +14,10 @@ extension Book { public enum CodingKeys: String, ModelKey { case id case authors + + public var modelType: Model.Type { + return Book.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Associations/BookAuthor+Schema.swift b/AmplifyTestCommon/Models/Associations/BookAuthor+Schema.swift index 515bebf8e1..b5b91d6fe4 100644 --- a/AmplifyTestCommon/Models/Associations/BookAuthor+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/BookAuthor+Schema.swift @@ -15,6 +15,10 @@ extension BookAuthor { case id case book case author + + public var modelType: Model.Type { + return BookAuthor.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift b/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift index ad14c65f42..1425cd2b95 100644 --- a/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift @@ -14,6 +14,10 @@ extension UserAccount { public enum CodingKeys: String, ModelKey { case id case profile + + public var modelType: Model.Type { + return UserAccount.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Associations/UserProfile+Schema.swift b/AmplifyTestCommon/Models/Associations/UserProfile+Schema.swift index d85257acbe..05f0d7a7c6 100644 --- a/AmplifyTestCommon/Models/Associations/UserProfile+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/UserProfile+Schema.swift @@ -14,6 +14,10 @@ extension UserProfile { public enum CodingKeys: String, ModelKey { case id case account + + public var modelType: Model.Type { + return UserProfile.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Comment+Schema.swift b/AmplifyTestCommon/Models/Comment+Schema.swift index bfb397c0f6..1bdaaf4453 100644 --- a/AmplifyTestCommon/Models/Comment+Schema.swift +++ b/AmplifyTestCommon/Models/Comment+Schema.swift @@ -10,27 +10,31 @@ import Amplify import Foundation extension Comment { - // MARK: - CodingKeys - public enum CodingKeys: String, ModelKey { - case id - case content - case createdAt - case post - } + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case createdAt + case post - public static let keys = CodingKeys.self - // MARK: - ModelSchema + public var modelType: Model.Type { + return Comment.self + } + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema - public static let schema = defineSchema { model in - let comment = Comment.keys + public static let schema = defineSchema { model in + let comment = Comment.keys - model.pluralName = "Comments" + model.pluralName = "Comments" - model.fields( - .id(), - .field(comment.content, is: .required, ofType: .string), - .field(comment.createdAt, is: .required, ofType: .dateTime), - .belongsTo(comment.post, is: .required, ofType: Post.self, targetName: "commentPostId") - ) + model.fields( + .id(), + .field(comment.content, is: .required, ofType: .string), + .field(comment.createdAt, is: .required, ofType: .dateTime), + .belongsTo(comment.post, is: .required, ofType: Post.self, targetName: "commentPostId") + ) } } diff --git a/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift b/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift index a1a65d8a89..140e56e0c5 100644 --- a/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift +++ b/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift @@ -9,15 +9,15 @@ import Amplify import Foundation /* -The schema used to codegen this model: + The schema used to codegen this model: type DeprecatedTodo @model { - id: ID! - description: String - note: Note + id: ID! + description: String + note: Note } type Note { - name: String! - color: String! + name: String! + color: String! } Amplify CLI version used is less than 4.21.4. `.customType` has since been replaced with `.embedded(type)` and @@ -26,40 +26,44 @@ The schema used to codegen this model: */ public struct DeprecatedTodo: Model { - public let id: String - public var description: String? - public var note: Note? + public let id: String + public var description: String? + public var note: Note? - public init(id: String = UUID().uuidString, - description: String? = nil, - note: Note? = nil) { - self.id = id - self.description = description - self.note = note - } + public init(id: String = UUID().uuidString, + description: String? = nil, + note: Note? = nil) { + self.id = id + self.description = description + self.note = note + } } extension DeprecatedTodo { - // MARK: - CodingKeys - public enum CodingKeys: String, ModelKey { - case id - case description - case note - } + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case description + case note + + public var modelType: Model.Type { + return DeprecatedTodo.self + } + } - public static let keys = CodingKeys.self - // MARK: - ModelSchema + public static let keys = CodingKeys.self + // MARK: - ModelSchema - public static let schema = defineSchema { model in - let deprecatedTodo = DeprecatedTodo.keys + public static let schema = defineSchema { model in + let deprecatedTodo = DeprecatedTodo.keys - model.pluralName = "DeprecatedTodos" + model.pluralName = "DeprecatedTodos" - model.fields( - .id(), - .field(deprecatedTodo.description, is: .optional, ofType: .string), - .field(deprecatedTodo.note, is: .optional, ofType: .customType(Note.self)) - ) + model.fields( + .id(), + .field(deprecatedTodo.description, is: .optional, ofType: .string), + .field(deprecatedTodo.note, is: .optional, ofType: .customType(Note.self)) + ) } } diff --git a/AmplifyTestCommon/Models/MockModels.swift b/AmplifyTestCommon/Models/MockModels.swift index f92403b404..7312ca69b1 100644 --- a/AmplifyTestCommon/Models/MockModels.swift +++ b/AmplifyTestCommon/Models/MockModels.swift @@ -20,6 +20,10 @@ public struct MockSynced: Model { public enum CodingKeys: String, ModelKey { case id + + public var modelType: Model.Type { + return MockSynced.self + } } public static let keys = CodingKeys.self @@ -46,6 +50,10 @@ public struct MockUnsynced: Model { public enum CodingKeys: String, ModelKey { case id + + public var modelType: Model.Type { + return MockUnsynced.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift b/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift index aaff4c88d1..94cb85f490 100644 --- a/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift +++ b/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift @@ -62,6 +62,11 @@ extension DynamicEmbedded { public enum CodingKeys: String, ModelKey { case values + + public var modelType: Model.Type { + // swiftlint:disable:next force_cast + return DynamicEmbedded.self as! Model.Type + } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/NonModel/DynamicModel.swift b/AmplifyTestCommon/Models/NonModel/DynamicModel.swift index b8c7163d83..dda04c8258 100644 --- a/AmplifyTestCommon/Models/NonModel/DynamicModel.swift +++ b/AmplifyTestCommon/Models/NonModel/DynamicModel.swift @@ -71,6 +71,10 @@ extension DynamicModel { public enum CodingKeys: String, ModelKey { case id case values + + public var modelType: Model.Type { + return DynamicModel.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift b/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift index 2b16606f8b..6bbc937789 100644 --- a/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift +++ b/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift @@ -10,31 +10,35 @@ import Amplify import Foundation extension Todo { - // MARK: - CodingKeys - public enum CodingKeys: String, ModelKey { - case id - case name - case description - case categories - case section - case stickies - } + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case description + case categories + case section + case stickies - public static let keys = CodingKeys.self - // MARK: - ModelSchema + public var modelType: Model.Type { + return Todo.self + } + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema - public static let schema = defineSchema { model in - let todo = Todo.keys + public static let schema = defineSchema { model in + let todo = Todo.keys - model.pluralName = "Todos" + model.pluralName = "Todos" - model.fields( - .id(), - .field(todo.name, is: .required, ofType: .string), - .field(todo.description, is: .optional, ofType: .string), - .field(todo.categories, is: .optional, ofType: .embeddedCollection(of: Category.self)), - .field(todo.section, is: .optional, ofType: .embedded(type: Section.self)), - .field(todo.stickies, is: .optional, ofType: .embeddedCollection(of: String.self)) - ) + model.fields( + .id(), + .field(todo.name, is: .required, ofType: .string), + .field(todo.description, is: .optional, ofType: .string), + .field(todo.categories, is: .optional, ofType: .embeddedCollection(of: Category.self)), + .field(todo.section, is: .optional, ofType: .embedded(type: Section.self)), + .field(todo.stickies, is: .optional, ofType: .embeddedCollection(of: String.self)) + ) } } diff --git a/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift b/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift index 234af3f402..967524634f 100644 --- a/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift +++ b/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift @@ -10,30 +10,34 @@ import Amplify import Foundation extension OGCScenarioBMGroupPost { - // MARK: - CodingKeys - public enum CodingKeys: String, ModelKey { - case id - case title - case owner - } - - public static let keys = CodingKeys.self - // MARK: - ModelSchema - - public static let schema = defineSchema { model in - let oGCScenarioBMGroupPost = OGCScenarioBMGroupPost.keys - - model.authRules = [ - rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", operations: [.create, .update, .delete, .read]), - rule(allow: .groups, groupClaim: "cognito:groups", groups: ["Admins", "HR"], operations: [.create, .update, .delete, .read]) - ] - - model.pluralName = "OGCScenarioBMGroupPosts" - - model.fields( - .id(), - .field(oGCScenarioBMGroupPost.title, is: .required, ofType: .string), - .field(oGCScenarioBMGroupPost.owner, is: .optional, ofType: .string) - ) + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case title + case owner + + public var modelType: Model.Type { + return OGCScenarioBMGroupPost.self + } + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let oGCScenarioBMGroupPost = OGCScenarioBMGroupPost.keys + + model.authRules = [ + rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", operations: [.create, .update, .delete, .read]), + rule(allow: .groups, groupClaim: "cognito:groups", groups: ["Admins", "HR"], operations: [.create, .update, .delete, .read]) + ] + + model.pluralName = "OGCScenarioBMGroupPosts" + + model.fields( + .id(), + .field(oGCScenarioBMGroupPost.title, is: .required, ofType: .string), + .field(oGCScenarioBMGroupPost.owner, is: .optional, ofType: .string) + ) } } diff --git a/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift b/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift index e37a68e96f..b1745e6577 100644 --- a/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift +++ b/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift @@ -10,30 +10,34 @@ import Amplify import Foundation extension OGCScenarioBPost { - // MARK: - CodingKeys - public enum CodingKeys: String, ModelKey { - case id - case title - case owner - } - - public static let keys = CodingKeys.self - // MARK: - ModelSchema - - public static let schema = defineSchema { model in - let oGCScenarioBPost = OGCScenarioBPost.keys - - model.authRules = [ - rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", operations: [.create, .update, .delete, .read]), - rule(allow: .groups, groupClaim: "cognito:groups", groups: ["Admins"], operations: [.create, .update, .delete, .read]) - ] - - model.pluralName = "OGCScenarioBPosts" - - model.fields( - .id(), - .field(oGCScenarioBPost.title, is: .required, ofType: .string), - .field(oGCScenarioBPost.owner, is: .optional, ofType: .string) - ) + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case title + case owner + + public var modelType: Model.Type { + return OGCScenarioBPost.self + } + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let oGCScenarioBPost = OGCScenarioBPost.keys + + model.authRules = [ + rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", operations: [.create, .update, .delete, .read]), + rule(allow: .groups, groupClaim: "cognito:groups", groups: ["Admins"], operations: [.create, .update, .delete, .read]) + ] + + model.pluralName = "OGCScenarioBPosts" + + model.fields( + .id(), + .field(oGCScenarioBPost.title, is: .required, ofType: .string), + .field(oGCScenarioBPost.owner, is: .optional, ofType: .string) + ) } } diff --git a/AmplifyTestCommon/Models/Post+Schema.swift b/AmplifyTestCommon/Models/Post+Schema.swift index 09532d3b0d..f53c0a542c 100644 --- a/AmplifyTestCommon/Models/Post+Schema.swift +++ b/AmplifyTestCommon/Models/Post+Schema.swift @@ -10,37 +10,41 @@ import Amplify import Foundation extension Post { - // MARK: - CodingKeys - public enum CodingKeys: String, ModelKey { - case id - case title - case content - case createdAt - case updatedAt - case draft - case rating - case status - case comments - } + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case title + case content + case createdAt + case updatedAt + case draft + case rating + case status + case comments - public static let keys = CodingKeys.self - // MARK: - ModelSchema + public var modelType: Model.Type { + return Post.self + } + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema - public static let schema = defineSchema { model in - let post = Post.keys + public static let schema = defineSchema { model in + let post = Post.keys - model.pluralName = "Posts" + model.pluralName = "Posts" - model.fields( - .id(), - .field(post.title, is: .required, ofType: .string), - .field(post.content, is: .required, ofType: .string), - .field(post.createdAt, is: .required, ofType: .dateTime), - .field(post.updatedAt, is: .optional, ofType: .dateTime), - .field(post.draft, is: .optional, ofType: .bool), - .field(post.rating, is: .optional, ofType: .double), - .field(post.status, is: .optional, ofType: .enum(type: PostStatus.self)), - .hasMany(post.comments, is: .optional, ofType: Comment.self, associatedWith: Comment.keys.post) - ) + model.fields( + .id(), + .field(post.title, is: .required, ofType: .string), + .field(post.content, is: .required, ofType: .string), + .field(post.createdAt, is: .required, ofType: .dateTime), + .field(post.updatedAt, is: .optional, ofType: .dateTime), + .field(post.draft, is: .optional, ofType: .bool), + .field(post.rating, is: .optional, ofType: .double), + .field(post.status, is: .optional, ofType: .enum(type: PostStatus.self)), + .hasMany(post.comments, is: .optional, ofType: Comment.self, associatedWith: Comment.keys.post) + ) } } diff --git a/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift b/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift index 4c2168e6e1..277f1755f1 100644 --- a/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift +++ b/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift @@ -10,27 +10,31 @@ import Amplify import Foundation extension ScenarioATest6Post { - // MARK: - CodingKeys - public enum CodingKeys: String, ModelKey { - case id - case title - } + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case title - public static let keys = CodingKeys.self - // MARK: - ModelSchema + public var modelType: Model.Type { + return ScenarioATest6Post.self + } + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema - public static let schema = defineSchema { model in - let scenarioATest6Post = ScenarioATest6Post.keys + public static let schema = defineSchema { model in + let scenarioATest6Post = ScenarioATest6Post.keys - model.authRules = [ - rule(allow: .owner, ownerField: "owner", identityClaim: "sub", operations: [.create, .update, .delete, .read]) - ] + model.authRules = [ + rule(allow: .owner, ownerField: "owner", identityClaim: "sub", operations: [.create, .update, .delete, .read]) + ] - model.pluralName = "ScenarioATest6Posts" + model.pluralName = "ScenarioATest6Posts" - model.fields( - .id(), - .field(scenarioATest6Post.title, is: .required, ofType: .string) - ) + model.fields( + .id(), + .field(scenarioATest6Post.title, is: .required, ofType: .string) + ) } } diff --git a/AmplifyTestCommon/Models/User+Schema.swift b/AmplifyTestCommon/Models/User+Schema.swift index ba7e7fae45..a22039f1f0 100644 --- a/AmplifyTestCommon/Models/User+Schema.swift +++ b/AmplifyTestCommon/Models/User+Schema.swift @@ -10,27 +10,31 @@ import Amplify import Foundation extension User { - // MARK: - CodingKeys - public enum CodingKeys: String, ModelKey { - case id - case name - case following - case followers - } + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case following + case followers - public static let keys = CodingKeys.self - // MARK: - ModelSchema + public var modelType: Model.Type { + return User.self + } + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema - public static let schema = defineSchema { model in - let user = User.keys + public static let schema = defineSchema { model in + let user = User.keys - model.pluralName = "Users" + model.pluralName = "Users" - model.fields( - .id(), - .field(user.name, is: .required, ofType: .string), - .hasMany(user.following, is: .optional, ofType: UserFollowing.self, associatedWith: UserFollowing.keys.user), - .hasMany(user.followers, is: .optional, ofType: UserFollowers.self, associatedWith: UserFollowers.keys.user) - ) + model.fields( + .id(), + .field(user.name, is: .required, ofType: .string), + .hasMany(user.following, is: .optional, ofType: UserFollowing.self, associatedWith: UserFollowing.keys.user), + .hasMany(user.followers, is: .optional, ofType: UserFollowers.self, associatedWith: UserFollowers.keys.user) + ) } } diff --git a/AmplifyTestCommon/Models/UserFollowers+Schema.swift b/AmplifyTestCommon/Models/UserFollowers+Schema.swift index ad68d9a3e3..b5e8532054 100644 --- a/AmplifyTestCommon/Models/UserFollowers+Schema.swift +++ b/AmplifyTestCommon/Models/UserFollowers+Schema.swift @@ -10,25 +10,29 @@ import Amplify import Foundation extension UserFollowers { - // MARK: - CodingKeys - public enum CodingKeys: String, ModelKey { - case id - case user - case followersUser - } + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case user + case followersUser - public static let keys = CodingKeys.self - // MARK: - ModelSchema + public var modelType: Model.Type { + return UserFollowers.self + } + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema - public static let schema = defineSchema { model in - let userFollowers = UserFollowers.keys + public static let schema = defineSchema { model in + let userFollowers = UserFollowers.keys - model.pluralName = "UserFollowers" + model.pluralName = "UserFollowers" - model.fields( - .id(), - .belongsTo(userFollowers.user, is: .optional, ofType: User.self, targetName: "userFollowersUserId"), - .belongsTo(userFollowers.followersUser, is: .optional, ofType: User.self, targetName: "userFollowersFollowersUserId") - ) + model.fields( + .id(), + .belongsTo(userFollowers.user, is: .optional, ofType: User.self, targetName: "userFollowersUserId"), + .belongsTo(userFollowers.followersUser, is: .optional, ofType: User.self, targetName: "userFollowersFollowersUserId") + ) } } diff --git a/AmplifyTestCommon/Models/UserFollowing+Schema.swift b/AmplifyTestCommon/Models/UserFollowing+Schema.swift index 8e84c88fba..07d7089e50 100644 --- a/AmplifyTestCommon/Models/UserFollowing+Schema.swift +++ b/AmplifyTestCommon/Models/UserFollowing+Schema.swift @@ -10,25 +10,29 @@ import Amplify import Foundation extension UserFollowing { - // MARK: - CodingKeys - public enum CodingKeys: String, ModelKey { - case id - case user - case followingUser - } + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case user + case followingUser - public static let keys = CodingKeys.self - // MARK: - ModelSchema + public var modelType: Model.Type { + return UserFollowing.self + } + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema - public static let schema = defineSchema { model in - let userFollowing = UserFollowing.keys + public static let schema = defineSchema { model in + let userFollowing = UserFollowing.keys - model.pluralName = "UserFollowings" + model.pluralName = "UserFollowings" - model.fields( - .id(), - .belongsTo(userFollowing.user, is: .optional, ofType: User.self, targetName: "userFollowingUserId"), - .belongsTo(userFollowing.followingUser, is: .optional, ofType: User.self, targetName: "userFollowingFollowingUserId") - ) + model.fields( + .id(), + .belongsTo(userFollowing.user, is: .optional, ofType: User.self, targetName: "userFollowingUserId"), + .belongsTo(userFollowing.followingUser, is: .optional, ofType: User.self, targetName: "userFollowingFollowingUserId") + ) } } diff --git a/Podfile.lock b/Podfile.lock index d87b647832..7de3d5855b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -63,4 +63,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: a2acde35ab1bc6b80b362106cfda70905a6a840f -COCOAPODS: 1.9.3 +COCOAPODS: 1.10.0 From 407cbbc77b0820a4dacf188ecb45d0a4c94285ce Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Tue, 10 Nov 2020 20:00:00 -0800 Subject: [PATCH 03/14] update AWSPluginsCore --- .../Schema/ModelSchema+Definition.swift | 10 -- .../Categories/DataStore/Query/ModelKey.swift | 1 - .../ModelSync/ModelSyncMetadata+Schema.swift | 2 +- .../Model/AnyModel/AnyModelTester.swift | 4 + .../ModelMultipleOwnerAuthRuleTests.swift | 4 + .../ModelReadUpdateAuthRuleTests.swift | 4 + ...lWithOwnerAuthAndGroupWithGroupClaim.swift | 98 ++++++++++--------- .../ModelWithOwnerAuthAndMultiGroup.swift | 4 + .../ModelWithOwnerFieldAuthRuleTests.swift | 4 + .../MockAWSAuthService.swift | 6 +- 10 files changed, 75 insertions(+), 62 deletions(-) diff --git a/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Definition.swift b/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Definition.swift index 1daae1d4eb..80d285edc3 100644 --- a/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Definition.swift +++ b/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Definition.swift @@ -121,16 +121,6 @@ public struct ModelSchemaDefinition { public mutating func fields(_ fields: ModelFieldDefinition...) { fields.forEach { definition in let field = definition.modelField -// switch field.association { -// case .belongsTo(_, let targetName): -// guard let targetName = targetName else { -// return -// } -// self.fields[targetName] = field -// return -// default: -// break -// } self.fields[field.name] = field } } diff --git a/Amplify/Categories/DataStore/Query/ModelKey.swift b/Amplify/Categories/DataStore/Query/ModelKey.swift index fea75527cb..3602df7d6c 100644 --- a/Amplify/Categories/DataStore/Query/ModelKey.swift +++ b/Amplify/Categories/DataStore/Query/ModelKey.swift @@ -78,7 +78,6 @@ extension CodingKey where Self: ModelKey { } public static func == (key: Self, value: Persistable?) -> QueryPredicateOperation { - return key.eq(value) } diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift b/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift index a1cd5962c1..8affa40611 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift @@ -15,7 +15,7 @@ extension ModelSyncMetadata { public enum CodingKeys: String, ModelKey { case id case lastSync - + public var modelType: Model.Type { return ModelSyncMetadata.self } diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift index ff9ce6285b..7a4efe4baa 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift @@ -28,6 +28,10 @@ extension AnyModelTester { case id case stringProperty case intProperty + + public var modelType: Model.Type { + return AnyModelTester.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift index 2552236278..1a4ca5c14d 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift @@ -37,6 +37,10 @@ public struct ModelMultipleOwner: Model { case id case content case editors + + public var modelType: Model.Type { + return ModelMultipleOwner.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift index 784b1afc00..365aee5349 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift @@ -31,6 +31,10 @@ public struct ModelReadUpdateField: Model { public enum CodingKeys: String, ModelKey { case id case content + + public var modelType: Model.Type { + return ModelReadUpdateField.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift index a16ae66e89..395461ab51 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift @@ -13,63 +13,67 @@ import XCTest /* type OIDCGroupPost - @model - @auth( - rules: [ - { allow: owner, provider: oidc, identityClaim: "sub"}, - { allow: groups, provider: oidc, groups: ["Admins"], - groupClaim: "https://myapp.com/claims/groups"} - ] - ) { - id: ID! - title: String! - owner: String + @model + @auth( + rules: [ + { allow: owner, provider: oidc, identityClaim: "sub"}, + { allow: groups, provider: oidc, groups: ["Admins"], + groupClaim: "https://myapp.com/claims/groups"} + ] + ) { + id: ID! + title: String! + owner: String } */ public struct OIDCGroupPost: Model { - public let id: String - public var title: String - public var owner: String? - - public init(id: String = UUID().uuidString, - title: String, - owner: String? = nil) { - self.id = id - self.title = title - self.owner = owner - } + public let id: String + public var title: String + public var owner: String? + + public init(id: String = UUID().uuidString, + title: String, + owner: String? = nil) { + self.id = id + self.title = title + self.owner = owner + } // MARK: - CodingKeys - public enum CodingKeys: String, ModelKey { - case id - case title - case owner + public enum CodingKeys: String, ModelKey { + case id + case title + case owner + + public var modelType: Model.Type { + return OIDCGroupPost.self + } } public static let keys = CodingKeys.self public static let schema = defineSchema { model in - let oIDCGroupPost = OIDCGroupPost.keys - - model.authRules = [ - rule(allow: .owner, - ownerField: "owner", - identityClaim: "sub", - operations: [.create, .update, .delete, .read]), - rule(allow: .groups, - groupClaim: "https://myapp.com/claims/groups", - groups: ["Admins"], - operations: [.create, .update, .delete, .read]) - ] - - model.pluralName = "OIDCGroupPosts" - - model.fields( - .id(), - .field(oIDCGroupPost.title, is: .required, ofType: .string), - .field(oIDCGroupPost.owner, is: .optional, ofType: .string) - ) - } + let oIDCGroupPost = OIDCGroupPost.keys + + model.authRules = [ + rule(allow: .owner, + ownerField: "owner", + identityClaim: "sub", + operations: [.create, .update, .delete, .read]), + rule(allow: .groups, + groupClaim: "https://myapp.com/claims/groups", + groups: ["Admins"], + operations: [.create, .update, .delete, .read]) + ] + + model.pluralName = "OIDCGroupPosts" + + model.fields( + .id(), + .field(oIDCGroupPost.title, is: .required, ofType: .string), + .field(oIDCGroupPost.owner, is: .optional, ofType: .string) + ) + } } class ModelWithOwnerAuthAndGroupWithGroupClaim: XCTestCase { diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift index c1b7832c60..07d111bc16 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift @@ -46,6 +46,10 @@ public struct OIDCMultiGroupPost: Model { case id case title case owner + + public var modelType: Model.Type { + return OIDCMultiGroupPost.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift index 66bc710c7e..2445211640 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift @@ -36,6 +36,10 @@ public struct ModelWithOwnerField: Model { case id case content case author + + public var modelType: Model.Type { + return ModelWithOwnerField.self + } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsTestCommon/MockAWSAuthService.swift b/AmplifyPlugins/Core/AWSPluginsTestCommon/MockAWSAuthService.swift index f7c2d0b020..5730eadb8d 100644 --- a/AmplifyPlugins/Core/AWSPluginsTestCommon/MockAWSAuthService.swift +++ b/AmplifyPlugins/Core/AWSPluginsTestCommon/MockAWSAuthService.swift @@ -16,7 +16,7 @@ public class MockAWSAuthService: AWSAuthServiceBehavior { var getTokenClaimsError: AuthError? var identityId: String? var token: String? - var tokenClaims: [String : AnyObject]? + var tokenClaims: [String: AnyObject]? public func configure() { } @@ -45,10 +45,10 @@ public class MockAWSAuthService: AWSAuthServiceBehavior { return .success(token ?? "token") } - public func getTokenClaims(tokenString: String) -> Result<[String : AnyObject], AuthError> { + public func getTokenClaims(tokenString: String) -> Result<[String: AnyObject], AuthError> { if let error = getTokenClaimsError { return .failure(error) } - return .success(tokenClaims ?? ["":"" as AnyObject]) + return .success(tokenClaims ?? ["": "" as AnyObject]) } } From ad6ebf410d5502614147a040a0b639e9524d8502 Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Wed, 11 Nov 2020 09:42:54 -0800 Subject: [PATCH 04/14] remove a force unwrap --- Amplify/Categories/DataStore/Query/ModelKey.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Amplify/Categories/DataStore/Query/ModelKey.swift b/Amplify/Categories/DataStore/Query/ModelKey.swift index 3602df7d6c..d322e6747d 100644 --- a/Amplify/Categories/DataStore/Query/ModelKey.swift +++ b/Amplify/Categories/DataStore/Query/ModelKey.swift @@ -41,7 +41,7 @@ extension CodingKey where Self: ModelKey { var columnName: String { switch modelType.schema.field(withName: stringValue)?.association { case .belongsTo(_, let targetName): - return targetName! + return targetName ?? stringValue default: return stringValue } From edb7d8f48b9f4973574c58363347de1fbcc12af0 Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Wed, 11 Nov 2020 10:20:59 -0800 Subject: [PATCH 05/14] added codingkeystests --- Amplify.xcodeproj/project.pbxproj | 6 ++++- .../DataStore/CodingKeysTests.swift | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 AmplifyTests/CategoryTests/DataStore/CodingKeysTests.swift diff --git a/Amplify.xcodeproj/project.pbxproj b/Amplify.xcodeproj/project.pbxproj index 6cdc329864..af3700bd53 100755 --- a/Amplify.xcodeproj/project.pbxproj +++ b/Amplify.xcodeproj/project.pbxproj @@ -414,6 +414,7 @@ B9FAA180238FBB5D009414B4 /* Model+Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9FAA17F238FBB5D009414B4 /* Model+Array.swift */; }; B9FB05F82383740D00DE1FD4 /* DataStoreStatement.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9FB05F72383740D00DE1FD4 /* DataStoreStatement.swift */; }; D83C5160248964780091548E /* ModelGraphQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D83C515F248964780091548E /* ModelGraphQLTests.swift */; }; + D84CF107255C5CA8007B96A9 /* CodingKeysTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84CF106255C5CA8007B96A9 /* CodingKeysTests.swift */; }; D8DD7A1D24A1CCCD001C49FD /* QuerySortInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8DD7A1C24A1CCCD001C49FD /* QuerySortInput.swift */; }; FA00F68824DA37EE003E8A71 /* AuthCategoryBehavior+Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA00F68724DA37EE003E8A71 /* AuthCategoryBehavior+Combine.swift */; }; FA00F68A24DA3A43003E8A71 /* AuthCategoryDeviceBehavior+Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA00F68924DA3A43003E8A71 /* AuthCategoryDeviceBehavior+Combine.swift */; }; @@ -1263,6 +1264,7 @@ D5363CAF9EFAA822FED56808 /* Pods_Amplify_AWSPluginsCore_AWSPluginsTestConfigs_AWSPluginsTestCommon.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Amplify_AWSPluginsCore_AWSPluginsTestConfigs_AWSPluginsTestCommon.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D5521D5FA66340943C39C451 /* Pods-Amplify-AmplifyAWSPlugins-AWSPluginsCore-AWSAPICategoryPlugin.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Amplify-AmplifyAWSPlugins-AWSPluginsCore-AWSAPICategoryPlugin.debug.xcconfig"; path = "Target Support Files/Pods-Amplify-AmplifyAWSPlugins-AWSPluginsCore-AWSAPICategoryPlugin/Pods-Amplify-AmplifyAWSPlugins-AWSPluginsCore-AWSAPICategoryPlugin.debug.xcconfig"; sourceTree = ""; }; D83C515F248964780091548E /* ModelGraphQLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelGraphQLTests.swift; sourceTree = ""; }; + D84CF106255C5CA8007B96A9 /* CodingKeysTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodingKeysTests.swift; sourceTree = ""; }; D8DD7A1C24A1CCCD001C49FD /* QuerySortInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuerySortInput.swift; sourceTree = ""; }; DD2486414D63230FF39130C7 /* Pods-Amplify-AWSPluginsCore.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Amplify-AWSPluginsCore.debug.xcconfig"; path = "Target Support Files/Pods-Amplify-AWSPluginsCore/Pods-Amplify-AWSPluginsCore.debug.xcconfig"; sourceTree = ""; }; DEEB82A328223C60557B75C1 /* Pods-Amplify-AmplifyAWSPlugins-AWSPluginsCore-AWSPinpointAnalyticsPlugin.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Amplify-AmplifyAWSPlugins-AWSPluginsCore-AWSPinpointAnalyticsPlugin.release.xcconfig"; path = "Target Support Files/Pods-Amplify-AmplifyAWSPlugins-AWSPluginsCore-AWSPinpointAnalyticsPlugin/Pods-Amplify-AmplifyAWSPlugins-AWSPluginsCore-AWSPinpointAnalyticsPlugin.release.xcconfig"; sourceTree = ""; }; @@ -3396,11 +3398,12 @@ children = ( FAD3937923820CDB00463F5E /* DataStoreCategoryClientAPITests.swift */, FAD3937C23820D0200463F5E /* DataStoreCategoryConfigurationTests.swift */, + B4944D51251C141200BF0BFE /* JSONValueHolderTest.swift */, + D84CF106255C5CA8007B96A9 /* CodingKeysTests.swift */, FAE414602399A6A500CE94C2 /* ModelRegistryTests.swift */, B99EF4B423DB020C00D821BC /* TemporalComparableTests.swift */, B9AF547D23F37DF20059E6C4 /* TemporalOperationTests.swift */, B91A87A323D64B0F0049A12F /* TemporalTests.swift */, - B4944D51251C141200BF0BFE /* JSONValueHolderTest.swift */, ); path = DataStore; sourceTree = ""; @@ -4814,6 +4817,7 @@ B91A87A423D64B0F0049A12F /* TemporalTests.swift in Sources */, FA00F69024DA3F95003E8A71 /* HubCombineTests.swift in Sources */, FA5D76AF23947E9C00489864 /* Model+CodableTests.swift in Sources */, + D84CF107255C5CA8007B96A9 /* CodingKeysTests.swift in Sources */, FA58456B24DA31370028D65A /* AmplifyInProcessReportingOperationChainedTests.swift in Sources */, FA1B964E24BF5FA70002B90A /* AmplifyOperationCombineTests.swift in Sources */, FAAFAF3323904BA4002CF932 /* AtomicValue+NumericTests.swift in Sources */, diff --git a/AmplifyTests/CategoryTests/DataStore/CodingKeysTests.swift b/AmplifyTests/CategoryTests/DataStore/CodingKeysTests.swift new file mode 100644 index 0000000000..4549740510 --- /dev/null +++ b/AmplifyTests/CategoryTests/DataStore/CodingKeysTests.swift @@ -0,0 +1,24 @@ +// +// Copyright 2018-2020 Amazon.com, +// Inc. or its affiliates. All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import XCTest +import Amplify +@testable import AmplifyTestCommon + +class CodingKeysTests: XCTestCase { + + func testSchemaHasCorrectColumnName() throws { + let commentQPO: QueryPredicateOperation = Comment.keys.id == "1234" + XCTAssertEqual(commentQPO.field, "id") + } + + func testSchemaWithBelongsToHasCorrectColumnName() throws { + let commentQPO: QueryPredicateOperation = Comment.keys.post == "5678" + XCTAssertEqual(commentQPO.field, "commentPostId") + } + +} From be4abb414f80ea3b4aa93ae09805b616cf6f291f Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Thu, 12 Nov 2020 11:40:57 -0800 Subject: [PATCH 06/14] ModelKey protocol: changed from Model.Type to String --- Amplify/Categories/DataStore/Query/ModelKey.swift | 7 +++++-- .../DataStore/Subscribe/MutationEvent+Schema.swift | 4 ++-- .../Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift | 4 ++-- .../Sync/ModelSync/ModelSyncMetadata+Schema.swift | 4 ++-- .../Sync/MutationSync/MutationSyncMetadata+Schema.swift | 4 ++-- .../Model/AnyModel/AnyModelTester.swift | 4 ++-- .../ModelMultipleOwnerAuthRuleTests.swift | 4 ++-- .../AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift | 4 ++-- .../ModelWithOwnerAuthAndGroupWithGroupClaim.swift | 4 ++-- .../ModelWithOwnerAuthAndMultiGroup.swift | 4 ++-- .../ModelWithOwnerFieldAuthRuleTests.swift | 4 ++-- .../Models/DynamicModel.swift | 4 ++-- .../Models/ExampleWithEveryType+Schema.swift | 4 ++-- AmplifyTestCommon/Models/Article+Schema.swift | 4 ++-- AmplifyTestCommon/Models/Associations/Author+Schema.swift | 4 ++-- AmplifyTestCommon/Models/Associations/Book+Schema.swift | 4 ++-- .../Models/Associations/BookAuthor+Schema.swift | 4 ++-- .../Models/Associations/UserAccount+Schema.swift | 4 ++-- .../Models/Associations/UserProfile+Schema.swift | 4 ++-- AmplifyTestCommon/Models/Comment+Schema.swift | 4 ++-- AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift | 4 ++-- AmplifyTestCommon/Models/MockModels.swift | 8 ++++---- AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift | 4 ++-- AmplifyTestCommon/Models/NonModel/DynamicModel.swift | 4 ++-- AmplifyTestCommon/Models/NonModel/Todo+Schema.swift | 4 ++-- .../Models/OGCScenarioBMGroupPost+Schema.swift | 4 ++-- AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift | 4 ++-- AmplifyTestCommon/Models/Post+Schema.swift | 4 ++-- AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift | 4 ++-- AmplifyTestCommon/Models/User+Schema.swift | 4 ++-- AmplifyTestCommon/Models/UserFollowers+Schema.swift | 4 ++-- AmplifyTestCommon/Models/UserFollowing+Schema.swift | 4 ++-- .../CategoryTests/DataStore/CodingKeysTests.swift | 2 ++ 33 files changed, 71 insertions(+), 66 deletions(-) diff --git a/Amplify/Categories/DataStore/Query/ModelKey.swift b/Amplify/Categories/DataStore/Query/ModelKey.swift index d322e6747d..91b509491e 100644 --- a/Amplify/Categories/DataStore/Query/ModelKey.swift +++ b/Amplify/Categories/DataStore/Query/ModelKey.swift @@ -33,13 +33,16 @@ import Foundation /// }) /// ``` public protocol ModelKey: CodingKey, CaseIterable, QueryFieldOperation { - var modelType: Model.Type { get } + var modelName: String { get } } extension CodingKey where Self: ModelKey { var columnName: String { - switch modelType.schema.field(withName: stringValue)?.association { + guard let modelSchema: ModelSchema = ModelRegistry.modelSchema(from: modelName) else { + return stringValue + } + switch modelSchema.field(withName: stringValue)?.association { case .belongsTo(_, let targetName): return targetName ?? stringValue default: diff --git a/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift b/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift index 590c32a812..a8ea6d89c9 100644 --- a/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift +++ b/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift @@ -19,8 +19,8 @@ extension MutationEvent { case inProcess case graphQLFilterJSON - public var modelType: Model.Type { - return MutationEvent.self + public var modelName: String { + return "MutationEvent" } } diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift index caa5735f4b..352231c303 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift @@ -32,8 +32,8 @@ extension AnyModel { case instance case modelName - public var modelType: Model.Type { - return AnyModel.self + public var modelName: String { + return "AnyModel" } } diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift b/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift index 8affa40611..4bfdad3f64 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift @@ -16,8 +16,8 @@ extension ModelSyncMetadata { case id case lastSync - public var modelType: Model.Type { - return ModelSyncMetadata.self + public var modelName: String { + return "ModelSyncMetadata" } } diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift b/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift index 27567d46a8..0ad85cb093 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift @@ -18,8 +18,8 @@ extension MutationSyncMetadata { case lastChangedAt case version - public var modelType: Model.Type { - return MutationSyncMetadata.self + public var modelName: String { + return "MutationSyncMetadata" } } diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift index 7a4efe4baa..35cdab7d7d 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift @@ -29,8 +29,8 @@ extension AnyModelTester { case stringProperty case intProperty - public var modelType: Model.Type { - return AnyModelTester.self + public var modelName: String { + return "AnyModelTester" } } diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift index 1a4ca5c14d..5f5798cbbc 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift @@ -38,8 +38,8 @@ public struct ModelMultipleOwner: Model { case content case editors - public var modelType: Model.Type { - return ModelMultipleOwner.self + public var modelName: String { + return "ModelMultipleOwner" } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift index 365aee5349..aacdfaf6ee 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift @@ -32,8 +32,8 @@ public struct ModelReadUpdateField: Model { case id case content - public var modelType: Model.Type { - return ModelReadUpdateField.self + public var modelName: String { + return "ModelReadUpdateField" } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift index 395461ab51..a4188128b4 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift @@ -46,8 +46,8 @@ public struct OIDCGroupPost: Model { case title case owner - public var modelType: Model.Type { - return OIDCGroupPost.self + public var modelName: String { + return "OIDCGroupPost" } } diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift index 07d111bc16..3f82736eec 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift @@ -47,8 +47,8 @@ public struct OIDCMultiGroupPost: Model { case title case owner - public var modelType: Model.Type { - return OIDCMultiGroupPost.self + public var modelName: String { + return "OIDCMultiGroupPost" } } diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift index 2445211640..1740745292 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift @@ -37,8 +37,8 @@ public struct ModelWithOwnerField: Model { case content case author - public var modelType: Model.Type { - return ModelWithOwnerField.self + public var modelName: String { + return "ModelWithOwnerField" } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift index e519fa4967..a0f582e4a5 100644 --- a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift +++ b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift @@ -83,8 +83,8 @@ extension DynamicModel { case id case values - public var modelType: Model.Type { - return DynamicModel.self + public var modelName: String { + return "DynamicModel" } } diff --git a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift index 3552f0f3a8..0f00fe4dbf 100644 --- a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift +++ b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift @@ -23,8 +23,8 @@ extension ExampleWithEveryType { case nonModelField case arrayOfStringsField - public var modelType: Model.Type { - return ExampleWithEveryType.self + public var modelName: String { + return "ExampleWithEveryType" } } diff --git a/AmplifyTestCommon/Models/Article+Schema.swift b/AmplifyTestCommon/Models/Article+Schema.swift index 7c5e3c1eba..7b116b62f8 100644 --- a/AmplifyTestCommon/Models/Article+Schema.swift +++ b/AmplifyTestCommon/Models/Article+Schema.swift @@ -18,8 +18,8 @@ extension Article { case owner case authorNotes - public var modelType: Model.Type { - return Article.self + public var modelName: String { + return "Article" } } diff --git a/AmplifyTestCommon/Models/Associations/Author+Schema.swift b/AmplifyTestCommon/Models/Associations/Author+Schema.swift index 627955c90f..5cb8465526 100644 --- a/AmplifyTestCommon/Models/Associations/Author+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/Author+Schema.swift @@ -15,8 +15,8 @@ extension Author { case id case books - public var modelType: Model.Type { - return Author.self + public var modelName: String { + return "Author" } } diff --git a/AmplifyTestCommon/Models/Associations/Book+Schema.swift b/AmplifyTestCommon/Models/Associations/Book+Schema.swift index 536408382d..7056fcab9a 100644 --- a/AmplifyTestCommon/Models/Associations/Book+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/Book+Schema.swift @@ -15,8 +15,8 @@ extension Book { case id case authors - public var modelType: Model.Type { - return Book.self + public var modelName: String { + return "Book" } } diff --git a/AmplifyTestCommon/Models/Associations/BookAuthor+Schema.swift b/AmplifyTestCommon/Models/Associations/BookAuthor+Schema.swift index b5b91d6fe4..44322309b2 100644 --- a/AmplifyTestCommon/Models/Associations/BookAuthor+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/BookAuthor+Schema.swift @@ -16,8 +16,8 @@ extension BookAuthor { case book case author - public var modelType: Model.Type { - return BookAuthor.self + public var modelName: String { + return "BookAuthor" } } diff --git a/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift b/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift index 1425cd2b95..e3bd6c0239 100644 --- a/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift @@ -15,8 +15,8 @@ extension UserAccount { case id case profile - public var modelType: Model.Type { - return UserAccount.self + public var modelName: String { + return "UserAccount" } } diff --git a/AmplifyTestCommon/Models/Associations/UserProfile+Schema.swift b/AmplifyTestCommon/Models/Associations/UserProfile+Schema.swift index 05f0d7a7c6..64a80ead26 100644 --- a/AmplifyTestCommon/Models/Associations/UserProfile+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/UserProfile+Schema.swift @@ -15,8 +15,8 @@ extension UserProfile { case id case account - public var modelType: Model.Type { - return UserProfile.self + public var modelName: String { + return "UserProfile" } } diff --git a/AmplifyTestCommon/Models/Comment+Schema.swift b/AmplifyTestCommon/Models/Comment+Schema.swift index 1bdaaf4453..db765a70a4 100644 --- a/AmplifyTestCommon/Models/Comment+Schema.swift +++ b/AmplifyTestCommon/Models/Comment+Schema.swift @@ -17,8 +17,8 @@ extension Comment { case createdAt case post - public var modelType: Model.Type { - return Comment.self + public var modelName: String { + return "Comment" } } diff --git a/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift b/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift index 140e56e0c5..bfa48749fc 100644 --- a/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift +++ b/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift @@ -46,8 +46,8 @@ extension DeprecatedTodo { case description case note - public var modelType: Model.Type { - return DeprecatedTodo.self + public var modelName: String { + return "DeprecatedTodo" } } diff --git a/AmplifyTestCommon/Models/MockModels.swift b/AmplifyTestCommon/Models/MockModels.swift index 7312ca69b1..1d8328d671 100644 --- a/AmplifyTestCommon/Models/MockModels.swift +++ b/AmplifyTestCommon/Models/MockModels.swift @@ -21,8 +21,8 @@ public struct MockSynced: Model { public enum CodingKeys: String, ModelKey { case id - public var modelType: Model.Type { - return MockSynced.self + public var modelName: String { + return "MockSynced" } } @@ -51,8 +51,8 @@ public struct MockUnsynced: Model { public enum CodingKeys: String, ModelKey { case id - public var modelType: Model.Type { - return MockUnsynced.self + public var modelName: String { + return "MockUnsynced" } } diff --git a/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift b/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift index 94cb85f490..62384e82ca 100644 --- a/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift +++ b/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift @@ -63,9 +63,9 @@ extension DynamicEmbedded { public enum CodingKeys: String, ModelKey { case values - public var modelType: Model.Type { + public var modelName: String { // swiftlint:disable:next force_cast - return DynamicEmbedded.self as! Model.Type + return "DynamicEmbedded" } } diff --git a/AmplifyTestCommon/Models/NonModel/DynamicModel.swift b/AmplifyTestCommon/Models/NonModel/DynamicModel.swift index dda04c8258..0ca8f3c27a 100644 --- a/AmplifyTestCommon/Models/NonModel/DynamicModel.swift +++ b/AmplifyTestCommon/Models/NonModel/DynamicModel.swift @@ -72,8 +72,8 @@ extension DynamicModel { case id case values - public var modelType: Model.Type { - return DynamicModel.self + public var modelName: String { + return "DynamicModel" } } diff --git a/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift b/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift index 6bbc937789..78bc809e2c 100644 --- a/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift +++ b/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift @@ -19,8 +19,8 @@ extension Todo { case section case stickies - public var modelType: Model.Type { - return Todo.self + public var modelName: String { + return "Todo" } } diff --git a/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift b/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift index 967524634f..1fbcdd33cb 100644 --- a/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift +++ b/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift @@ -16,8 +16,8 @@ extension OGCScenarioBMGroupPost { case title case owner - public var modelType: Model.Type { - return OGCScenarioBMGroupPost.self + public var modelName: String { + return "OGCScenarioBMGroupPost" } } diff --git a/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift b/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift index b1745e6577..6889098c07 100644 --- a/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift +++ b/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift @@ -16,8 +16,8 @@ extension OGCScenarioBPost { case title case owner - public var modelType: Model.Type { - return OGCScenarioBPost.self + public var modelName: String { + return "OGCScenarioBPost" } } diff --git a/AmplifyTestCommon/Models/Post+Schema.swift b/AmplifyTestCommon/Models/Post+Schema.swift index f53c0a542c..3ce3464e60 100644 --- a/AmplifyTestCommon/Models/Post+Schema.swift +++ b/AmplifyTestCommon/Models/Post+Schema.swift @@ -22,8 +22,8 @@ extension Post { case status case comments - public var modelType: Model.Type { - return Post.self + public var modelName: String { + return "Post" } } diff --git a/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift b/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift index 277f1755f1..8ea7cc146b 100644 --- a/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift +++ b/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift @@ -15,8 +15,8 @@ extension ScenarioATest6Post { case id case title - public var modelType: Model.Type { - return ScenarioATest6Post.self + public var modelName: String { + return "ScenarioATest6Post" } } diff --git a/AmplifyTestCommon/Models/User+Schema.swift b/AmplifyTestCommon/Models/User+Schema.swift index a22039f1f0..1efaf1ff75 100644 --- a/AmplifyTestCommon/Models/User+Schema.swift +++ b/AmplifyTestCommon/Models/User+Schema.swift @@ -17,8 +17,8 @@ extension User { case following case followers - public var modelType: Model.Type { - return User.self + public var modelName: String { + return "User" } } diff --git a/AmplifyTestCommon/Models/UserFollowers+Schema.swift b/AmplifyTestCommon/Models/UserFollowers+Schema.swift index b5e8532054..4c175d67c5 100644 --- a/AmplifyTestCommon/Models/UserFollowers+Schema.swift +++ b/AmplifyTestCommon/Models/UserFollowers+Schema.swift @@ -16,8 +16,8 @@ extension UserFollowers { case user case followersUser - public var modelType: Model.Type { - return UserFollowers.self + public var modelName: String { + return "UserFollowers" } } diff --git a/AmplifyTestCommon/Models/UserFollowing+Schema.swift b/AmplifyTestCommon/Models/UserFollowing+Schema.swift index 07d7089e50..1008e39c4b 100644 --- a/AmplifyTestCommon/Models/UserFollowing+Schema.swift +++ b/AmplifyTestCommon/Models/UserFollowing+Schema.swift @@ -16,8 +16,8 @@ extension UserFollowing { case user case followingUser - public var modelType: Model.Type { - return UserFollowing.self + public var modelName: String { + return "UserFollowing" } } diff --git a/AmplifyTests/CategoryTests/DataStore/CodingKeysTests.swift b/AmplifyTests/CategoryTests/DataStore/CodingKeysTests.swift index 4549740510..ad0811c02b 100644 --- a/AmplifyTests/CategoryTests/DataStore/CodingKeysTests.swift +++ b/AmplifyTests/CategoryTests/DataStore/CodingKeysTests.swift @@ -12,11 +12,13 @@ import Amplify class CodingKeysTests: XCTestCase { func testSchemaHasCorrectColumnName() throws { + ModelRegistry.register(modelType: Comment.self) let commentQPO: QueryPredicateOperation = Comment.keys.id == "1234" XCTAssertEqual(commentQPO.field, "id") } func testSchemaWithBelongsToHasCorrectColumnName() throws { + ModelRegistry.register(modelType: Comment.self) let commentQPO: QueryPredicateOperation = Comment.keys.post == "5678" XCTAssertEqual(commentQPO.field, "commentPostId") } From 2ee40ca6796575dcdace11af04c57bc46500d3df Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Thu, 12 Nov 2020 13:44:12 -0800 Subject: [PATCH 07/14] added default implementation --- Amplify/Categories/DataStore/Query/ModelKey.swift | 4 ++++ .../DataStore/Subscribe/MutationEvent+Schema.swift | 4 ---- .../Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift | 4 ---- .../Sync/ModelSync/ModelSyncMetadata+Schema.swift | 4 ---- .../Sync/MutationSync/MutationSyncMetadata+Schema.swift | 4 ---- .../ModelMultipleOwnerAuthRuleTests.swift | 4 ---- .../AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift | 4 ---- .../ModelWithOwnerAuthAndGroupWithGroupClaim.swift | 4 ---- .../ModelWithOwnerAuthAndMultiGroup.swift | 4 ---- .../ModelWithOwnerFieldAuthRuleTests.swift | 4 ---- AmplifyTestCommon/Models/Article+Schema.swift | 4 ---- AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift | 4 ---- AmplifyTestCommon/Models/MockModels.swift | 8 -------- .../Models/OGCScenarioBMGroupPost+Schema.swift | 4 ---- AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift | 4 ---- AmplifyTestCommon/Models/Post+Schema.swift | 4 ---- AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift | 4 ---- AmplifyTestCommon/Models/User+Schema.swift | 4 ---- 18 files changed, 4 insertions(+), 72 deletions(-) diff --git a/Amplify/Categories/DataStore/Query/ModelKey.swift b/Amplify/Categories/DataStore/Query/ModelKey.swift index 91b509491e..6d57d109ad 100644 --- a/Amplify/Categories/DataStore/Query/ModelKey.swift +++ b/Amplify/Categories/DataStore/Query/ModelKey.swift @@ -36,6 +36,10 @@ public protocol ModelKey: CodingKey, CaseIterable, QueryFieldOperation { var modelName: String { get } } +extension ModelKey { + public var modelName: String { "" } +} + extension CodingKey where Self: ModelKey { var columnName: String { diff --git a/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift b/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift index a8ea6d89c9..6091800a9a 100644 --- a/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift +++ b/Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift @@ -18,10 +18,6 @@ extension MutationEvent { case version case inProcess case graphQLFilterJSON - - public var modelName: String { - return "MutationEvent" - } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift index 352231c303..1e2ea11703 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/AnyModel/AnyModel.swift @@ -31,10 +31,6 @@ extension AnyModel { case id case instance case modelName - - public var modelName: String { - return "AnyModel" - } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift b/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift index 4bfdad3f64..8cddb6cb4c 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata+Schema.swift @@ -15,10 +15,6 @@ extension ModelSyncMetadata { public enum CodingKeys: String, ModelKey { case id case lastSync - - public var modelName: String { - return "ModelSyncMetadata" - } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift b/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift index 0ad85cb093..3355ff3f8c 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift @@ -17,10 +17,6 @@ extension MutationSyncMetadata { case deleted case lastChangedAt case version - - public var modelName: String { - return "MutationSyncMetadata" - } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift index 5f5798cbbc..2552236278 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelMultipleOwnerAuthRuleTests.swift @@ -37,10 +37,6 @@ public struct ModelMultipleOwner: Model { case id case content case editors - - public var modelName: String { - return "ModelMultipleOwner" - } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift index aacdfaf6ee..784b1afc00 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelReadUpdateAuthRuleTests.swift @@ -31,10 +31,6 @@ public struct ModelReadUpdateField: Model { public enum CodingKeys: String, ModelKey { case id case content - - public var modelName: String { - return "ModelReadUpdateField" - } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift index a4188128b4..64e32a57e9 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift @@ -45,10 +45,6 @@ public struct OIDCGroupPost: Model { case id case title case owner - - public var modelName: String { - return "OIDCGroupPost" - } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift index 3f82736eec..c1b7832c60 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndMultiGroup.swift @@ -46,10 +46,6 @@ public struct OIDCMultiGroupPost: Model { case id case title case owner - - public var modelName: String { - return "OIDCMultiGroupPost" - } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift index 1740745292..66bc710c7e 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerFieldAuthRuleTests.swift @@ -36,10 +36,6 @@ public struct ModelWithOwnerField: Model { case id case content case author - - public var modelName: String { - return "ModelWithOwnerField" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Article+Schema.swift b/AmplifyTestCommon/Models/Article+Schema.swift index 7b116b62f8..93e4802b81 100644 --- a/AmplifyTestCommon/Models/Article+Schema.swift +++ b/AmplifyTestCommon/Models/Article+Schema.swift @@ -17,10 +17,6 @@ extension Article { case createdAt case owner case authorNotes - - public var modelName: String { - return "Article" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift b/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift index bfa48749fc..09e424f73f 100644 --- a/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift +++ b/AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift @@ -45,10 +45,6 @@ extension DeprecatedTodo { case id case description case note - - public var modelName: String { - return "DeprecatedTodo" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/MockModels.swift b/AmplifyTestCommon/Models/MockModels.swift index 1d8328d671..f92403b404 100644 --- a/AmplifyTestCommon/Models/MockModels.swift +++ b/AmplifyTestCommon/Models/MockModels.swift @@ -20,10 +20,6 @@ public struct MockSynced: Model { public enum CodingKeys: String, ModelKey { case id - - public var modelName: String { - return "MockSynced" - } } public static let keys = CodingKeys.self @@ -50,10 +46,6 @@ public struct MockUnsynced: Model { public enum CodingKeys: String, ModelKey { case id - - public var modelName: String { - return "MockUnsynced" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift b/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift index 1fbcdd33cb..b0f8fb7d03 100644 --- a/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift +++ b/AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift @@ -15,10 +15,6 @@ extension OGCScenarioBMGroupPost { case id case title case owner - - public var modelName: String { - return "OGCScenarioBMGroupPost" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift b/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift index 6889098c07..cd2b4623bf 100644 --- a/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift +++ b/AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift @@ -15,10 +15,6 @@ extension OGCScenarioBPost { case id case title case owner - - public var modelName: String { - return "OGCScenarioBPost" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Post+Schema.swift b/AmplifyTestCommon/Models/Post+Schema.swift index 3ce3464e60..adb8bf765f 100644 --- a/AmplifyTestCommon/Models/Post+Schema.swift +++ b/AmplifyTestCommon/Models/Post+Schema.swift @@ -21,10 +21,6 @@ extension Post { case rating case status case comments - - public var modelName: String { - return "Post" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift b/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift index 8ea7cc146b..ff2d7288d3 100644 --- a/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift +++ b/AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift @@ -14,10 +14,6 @@ extension ScenarioATest6Post { public enum CodingKeys: String, ModelKey { case id case title - - public var modelName: String { - return "ScenarioATest6Post" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/User+Schema.swift b/AmplifyTestCommon/Models/User+Schema.swift index 1efaf1ff75..9dded1389e 100644 --- a/AmplifyTestCommon/Models/User+Schema.swift +++ b/AmplifyTestCommon/Models/User+Schema.swift @@ -16,10 +16,6 @@ extension User { case name case following case followers - - public var modelName: String { - return "User" - } } public static let keys = CodingKeys.self From ca250b8d862f110431a6099c309ed56cf69975db Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Thu, 12 Nov 2020 13:51:12 -0800 Subject: [PATCH 08/14] updated struct that conforms to Model --- .../Models/DynamicModel.swift | 4 ---- .../Models/ExampleWithEveryType+Schema.swift | 4 ---- AmplifyTestCommon/Models/Associations/Author+Schema.swift | 4 ---- AmplifyTestCommon/Models/Associations/Book+Schema.swift | 4 ---- .../Models/Associations/UserAccount+Schema.swift | 4 ---- AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift | 5 ----- 6 files changed, 25 deletions(-) diff --git a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift index a0f582e4a5..f68e6469a6 100644 --- a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift +++ b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/DynamicModel.swift @@ -82,10 +82,6 @@ extension DynamicModel { public enum CodingKeys: String, ModelKey { case id case values - - public var modelName: String { - return "DynamicModel" - } } public static let keys = CodingKeys.self diff --git a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift index 0f00fe4dbf..d328f64315 100644 --- a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift +++ b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Models/ExampleWithEveryType+Schema.swift @@ -22,10 +22,6 @@ extension ExampleWithEveryType { case enumField case nonModelField case arrayOfStringsField - - public var modelName: String { - return "ExampleWithEveryType" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Associations/Author+Schema.swift b/AmplifyTestCommon/Models/Associations/Author+Schema.swift index 5cb8465526..6a525a8315 100644 --- a/AmplifyTestCommon/Models/Associations/Author+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/Author+Schema.swift @@ -14,10 +14,6 @@ extension Author { public enum CodingKeys: String, ModelKey { case id case books - - public var modelName: String { - return "Author" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Associations/Book+Schema.swift b/AmplifyTestCommon/Models/Associations/Book+Schema.swift index 7056fcab9a..4b7f852b1f 100644 --- a/AmplifyTestCommon/Models/Associations/Book+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/Book+Schema.swift @@ -14,10 +14,6 @@ extension Book { public enum CodingKeys: String, ModelKey { case id case authors - - public var modelName: String { - return "Book" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift b/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift index e3bd6c0239..ad14c65f42 100644 --- a/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift +++ b/AmplifyTestCommon/Models/Associations/UserAccount+Schema.swift @@ -14,10 +14,6 @@ extension UserAccount { public enum CodingKeys: String, ModelKey { case id case profile - - public var modelName: String { - return "UserAccount" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift b/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift index 62384e82ca..aaff4c88d1 100644 --- a/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift +++ b/AmplifyTestCommon/Models/NonModel/DynamicEmbedded.swift @@ -62,11 +62,6 @@ extension DynamicEmbedded { public enum CodingKeys: String, ModelKey { case values - - public var modelName: String { - // swiftlint:disable:next force_cast - return "DynamicEmbedded" - } } public static let keys = CodingKeys.self From 17cbe3b643981d40d70e0beb00f2473e623dea84 Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Thu, 12 Nov 2020 13:53:27 -0800 Subject: [PATCH 09/14] updated struct that conforms to Model --- .../AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift | 4 ---- AmplifyTestCommon/Models/NonModel/Todo+Schema.swift | 4 ---- 2 files changed, 8 deletions(-) diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift index 35cdab7d7d..ff9ce6285b 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/AnyModel/AnyModelTester.swift @@ -28,10 +28,6 @@ extension AnyModelTester { case id case stringProperty case intProperty - - public var modelName: String { - return "AnyModelTester" - } } public static let keys = CodingKeys.self diff --git a/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift b/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift index 78bc809e2c..d52d61905c 100644 --- a/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift +++ b/AmplifyTestCommon/Models/NonModel/Todo+Schema.swift @@ -18,10 +18,6 @@ extension Todo { case categories case section case stickies - - public var modelName: String { - return "Todo" - } } public static let keys = CodingKeys.self From 6ca393f38809cf3236329006072dfa6c17cd2dcb Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Fri, 13 Nov 2020 17:13:19 -0800 Subject: [PATCH 10/14] added two more tests and revert the changes in Podfile.lock --- .../GraphQLListQueryTests.swift | 85 +++++++++++++++++++ .../Core/SQLStatementTests.swift | 25 ++++++ AmplifyPlugins/DataStore/Podfile.lock | 2 +- Podfile.lock | 2 +- 4 files changed, 112 insertions(+), 2 deletions(-) diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/GraphQLDocument/GraphQLListQueryTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/GraphQLDocument/GraphQLListQueryTests.swift index 8912bea8d6..c02e024828 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/GraphQLDocument/GraphQLListQueryTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/GraphQLDocument/GraphQLListQueryTests.swift @@ -115,6 +115,91 @@ class GraphQLListQueryTests: XCTestCase { XCTAssertEqual(String(data: filterJSON!, encoding: .utf8), expectedFilterJSON) } + /// - Given: a `Model` type + /// - When: + /// - the model is of type `Comment` + /// - the model has no eager loaded connections + /// - the query is of type `.list` + /// - Then: + /// - check if the generated GraphQL document is valid query: + /// - it contains an `filter` argument of type `ModelCommentFilterInput` + /// - it is named `listComments` + /// - it has a list of fields, one of which is post that also has a list of fields with no nested models + /// - fields are wrapped with `items` + /// - check if generated GraphQL variables is valid: + /// - it contains the correct columnName `commentPostId` + func testListGraphQLQueryFromSimpleModelGivenQueryPredicateOnConnectedField() { + let comment = Comment.keys + let predicate = comment.id.eq("id") + && comment.post.eq("commentPostId") + + var documentBuilder = ModelBasedGraphQLDocumentBuilder(modelSchema: Comment.schema, operationType: .query) + documentBuilder.add(decorator: DirectiveNameDecorator(type: .list)) + documentBuilder.add(decorator: PaginationDecorator()) + documentBuilder.add(decorator: FilterDecorator(filter: predicate.graphQLFilter)) + let document = documentBuilder.build() + let expectedQueryDocument = """ + query ListComments($filter: ModelCommentFilterInput, $limit: Int) { + listComments(filter: $filter, limit: $limit) { + items { + id + content + createdAt + post { + id + content + createdAt + draft + rating + status + title + updatedAt + __typename + } + __typename + } + nextToken + } + } + """ + XCTAssertEqual(document.name, "listComments") + XCTAssertEqual(document.stringValue, expectedQueryDocument) + guard let variables = document.variables else { + XCTFail("The document doesn't contain variables") + return + } + XCTAssertNotNil(variables["limit"]) + XCTAssertEqual(variables["limit"] as? Int, 1_000) + + guard let filter = variables["filter"] as? GraphQLFilter else { + XCTFail("variables should contain a valid filter") + return + } + + // Test filter for a valid JSON format + let filterJSON = try? JSONSerialization.data(withJSONObject: filter, + options: .prettyPrinted) + XCTAssertNotNil(filterJSON) + + let expectedFilterJSON = """ + { + "and" : [ + { + "id" : { + "eq" : "id" + } + }, + { + "commentPostId" : { + "eq" : "commentPostId" + } + } + ] + } + """ + XCTAssertEqual(String(data: filterJSON!, encoding: .utf8), expectedFilterJSON) + } + func testListGraphQLQueryFromSimpleModelWithSyncEnabled() { let post = Post.keys let predicate = post.id.eq("id") && (post.title.beginsWith("Title") || post.content.contains("content")) diff --git a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Core/SQLStatementTests.swift b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Core/SQLStatementTests.swift index e9978be2ca..158c76b83a 100644 --- a/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Core/SQLStatementTests.swift +++ b/AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Core/SQLStatementTests.swift @@ -330,6 +330,31 @@ class SQLStatementTests: XCTestCase { XCTAssertEqual(statement.stringValue, expectedStatement) } + /// - Given: a `Model` type + /// - When: + /// - the model is of type `Comment` + /// - `QueryPredicate` on a connected field is given + /// - Then: + /// - check if the generated SQL statement is valid + /// - check if an inner join is added referencing `Post` + /// - check if a where with columnName `commentPostId` is generated + func testSelectStatementFromModelWhenQueryPredicateIsGiven() { + let statement = SelectStatement(from: Comment.schema, predicate: Comment.keys.post == "commentPostId") + let expectedStatement = """ + select + "root"."id" as "id", "root"."content" as "content", "root"."createdAt" as "createdAt", + "root"."commentPostId" as "commentPostId", "post"."id" as "post.id", "post"."content" as "post.content", + "post"."createdAt" as "post.createdAt", "post"."draft" as "post.draft", "post"."rating" as "post.rating", + "post"."status" as "post.status", "post"."title" as "post.title", "post"."updatedAt" as "post.updatedAt" + from Comment as "root" + inner join Post as "post" + on "post"."id" = "root"."commentPostId" + where 1 = 1 + and "root"."commentPostId" = ? + """ + XCTAssertEqual(statement.stringValue, expectedStatement) + } + // MARK: - Select Statements paginated /// - Given: a `Model` type and a `QueryPaginationInput` diff --git a/AmplifyPlugins/DataStore/Podfile.lock b/AmplifyPlugins/DataStore/Podfile.lock index e8fcef0614..f2b2765e80 100644 --- a/AmplifyPlugins/DataStore/Podfile.lock +++ b/AmplifyPlugins/DataStore/Podfile.lock @@ -122,4 +122,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 04860e414d616b67d24ed3346a60700f427764b9 -COCOAPODS: 1.10.0 +COCOAPODS: 1.9.3 diff --git a/Podfile.lock b/Podfile.lock index 5068c6e97e..24433a3492 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -63,4 +63,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: a2acde35ab1bc6b80b362106cfda70905a6a840f -COCOAPODS: 1.10.0 +COCOAPODS: 1.9.3 From 9cb73e2adb49427ec437ba0e8d9fb62349413cc5 Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Sun, 15 Nov 2020 11:38:56 -0800 Subject: [PATCH 11/14] foratted graphql --- ...lWithOwnerAuthAndGroupWithGroupClaim.swift | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift index 64e32a57e9..4d6416d715 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift @@ -13,17 +13,21 @@ import XCTest /* type OIDCGroupPost - @model - @auth( - rules: [ - { allow: owner, provider: oidc, identityClaim: "sub"}, - { allow: groups, provider: oidc, groups: ["Admins"], - groupClaim: "https://myapp.com/claims/groups"} - ] - ) { - id: ID! - title: String! - owner: String + @model + @auth( + rules: [ + { allow: owner, provider: oidc, identityClaim: "sub" } + { + allow: groups + provider: oidc + groups: ["Admins"] + groupClaim: "https://myapp.com/claims/groups" + } + ] + ) { + id: ID! + title: String! + owner: String } */ From fef2f1f7ed622e6212961ffe5710de6409654b7e Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Sun, 15 Nov 2020 13:47:06 -0800 Subject: [PATCH 12/14] added a print to output warning --- Amplify/Categories/DataStore/Query/ModelKey.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Amplify/Categories/DataStore/Query/ModelKey.swift b/Amplify/Categories/DataStore/Query/ModelKey.swift index 6d57d109ad..30a5700371 100644 --- a/Amplify/Categories/DataStore/Query/ModelKey.swift +++ b/Amplify/Categories/DataStore/Query/ModelKey.swift @@ -44,6 +44,7 @@ extension CodingKey where Self: ModelKey { var columnName: String { guard let modelSchema: ModelSchema = ModelRegistry.modelSchema(from: modelName) else { + print("Warning: Please upgrade to the latest version of Amplify CLI and rerun `amplify codegen models`") return stringValue } switch modelSchema.field(withName: stringValue)?.association { From f06b54fac4a8f96cbcddf4fcc9a550ce52893222 Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Mon, 16 Nov 2020 10:25:55 -0800 Subject: [PATCH 13/14] ModelKey conforms to DefaultLogger --- Amplify/Categories/DataStore/Query/ModelKey.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Amplify/Categories/DataStore/Query/ModelKey.swift b/Amplify/Categories/DataStore/Query/ModelKey.swift index 30a5700371..744446e3f2 100644 --- a/Amplify/Categories/DataStore/Query/ModelKey.swift +++ b/Amplify/Categories/DataStore/Query/ModelKey.swift @@ -32,7 +32,7 @@ import Foundation /// post.content != nil /// }) /// ``` -public protocol ModelKey: CodingKey, CaseIterable, QueryFieldOperation { +public protocol ModelKey: CodingKey, CaseIterable, QueryFieldOperation, DefaultLogger { var modelName: String { get } } @@ -44,7 +44,7 @@ extension CodingKey where Self: ModelKey { var columnName: String { guard let modelSchema: ModelSchema = ModelRegistry.modelSchema(from: modelName) else { - print("Warning: Please upgrade to the latest version of Amplify CLI and rerun `amplify codegen models`") + log.warn("Please upgrade to the latest version of Amplify CLI and rerun `amplify codegen models`") return stringValue } switch modelSchema.field(withName: stringValue)?.association { From 278a8c17a50eedc6c53d9c217d50c0f4a701b8f9 Mon Sep 17 00:00:00 2001 From: Guo <48600426+DongQuanRui@users.noreply.github.com> Date: Thu, 3 Dec 2020 13:23:30 -0800 Subject: [PATCH 14/14] removed one unit test in GraphQLListTest --- .../GraphQLListQueryTests.swift | 85 ------------------- 1 file changed, 85 deletions(-) diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/GraphQLDocument/GraphQLListQueryTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/GraphQLDocument/GraphQLListQueryTests.swift index c02e024828..8912bea8d6 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/GraphQLDocument/GraphQLListQueryTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/GraphQLDocument/GraphQLListQueryTests.swift @@ -115,91 +115,6 @@ class GraphQLListQueryTests: XCTestCase { XCTAssertEqual(String(data: filterJSON!, encoding: .utf8), expectedFilterJSON) } - /// - Given: a `Model` type - /// - When: - /// - the model is of type `Comment` - /// - the model has no eager loaded connections - /// - the query is of type `.list` - /// - Then: - /// - check if the generated GraphQL document is valid query: - /// - it contains an `filter` argument of type `ModelCommentFilterInput` - /// - it is named `listComments` - /// - it has a list of fields, one of which is post that also has a list of fields with no nested models - /// - fields are wrapped with `items` - /// - check if generated GraphQL variables is valid: - /// - it contains the correct columnName `commentPostId` - func testListGraphQLQueryFromSimpleModelGivenQueryPredicateOnConnectedField() { - let comment = Comment.keys - let predicate = comment.id.eq("id") - && comment.post.eq("commentPostId") - - var documentBuilder = ModelBasedGraphQLDocumentBuilder(modelSchema: Comment.schema, operationType: .query) - documentBuilder.add(decorator: DirectiveNameDecorator(type: .list)) - documentBuilder.add(decorator: PaginationDecorator()) - documentBuilder.add(decorator: FilterDecorator(filter: predicate.graphQLFilter)) - let document = documentBuilder.build() - let expectedQueryDocument = """ - query ListComments($filter: ModelCommentFilterInput, $limit: Int) { - listComments(filter: $filter, limit: $limit) { - items { - id - content - createdAt - post { - id - content - createdAt - draft - rating - status - title - updatedAt - __typename - } - __typename - } - nextToken - } - } - """ - XCTAssertEqual(document.name, "listComments") - XCTAssertEqual(document.stringValue, expectedQueryDocument) - guard let variables = document.variables else { - XCTFail("The document doesn't contain variables") - return - } - XCTAssertNotNil(variables["limit"]) - XCTAssertEqual(variables["limit"] as? Int, 1_000) - - guard let filter = variables["filter"] as? GraphQLFilter else { - XCTFail("variables should contain a valid filter") - return - } - - // Test filter for a valid JSON format - let filterJSON = try? JSONSerialization.data(withJSONObject: filter, - options: .prettyPrinted) - XCTAssertNotNil(filterJSON) - - let expectedFilterJSON = """ - { - "and" : [ - { - "id" : { - "eq" : "id" - } - }, - { - "commentPostId" : { - "eq" : "commentPostId" - } - } - ] - } - """ - XCTAssertEqual(String(data: filterJSON!, encoding: .utf8), expectedFilterJSON) - } - func testListGraphQLQueryFromSimpleModelWithSyncEnabled() { let post = Post.keys let predicate = post.id.eq("id") && (post.title.beginsWith("Title") || post.content.contains("content"))