Skip to content

Commit

Permalink
fix: Support new list name pluralization
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha committed Oct 5, 2021
1 parent 7cbbf22 commit db3e03a
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,27 @@ public enum ModelFieldNullability {
public struct ModelSchemaDefinition {

internal let name: String

@available(*, deprecated, message: "Use of pluralName is deprecated, use syncPluralName instead.")
public var pluralName: String?

public var listPluralName: String?
public var syncPluralName: String?

public var authRules: AuthRules
internal var fields: ModelFields
internal var attributes: [ModelAttribute]

init(name: String,
pluralName: String? = nil,
listPluralName: String? = nil,
syncPluralName: String? = nil,
authRules: AuthRules = [],
attributes: [ModelAttribute] = []) {
self.name = name
self.pluralName = pluralName
self.listPluralName = listPluralName
self.syncPluralName = syncPluralName
self.fields = [:] as ModelFields
self.authRules = authRules
self.attributes = attributes
Expand All @@ -154,6 +164,8 @@ public struct ModelSchemaDefinition {
internal func build() -> ModelSchema {
return ModelSchema(name: name,
pluralName: pluralName,
listPluralName: listPluralName,
syncPluralName: syncPluralName,
authRules: authRules,
attributes: attributes,
fields: fields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ public typealias ModelName = String
public struct ModelSchema {

public let name: String

@available(*, deprecated, message: "Use of pluralName is deprecated, use syncPluralName instead.")
public let pluralName: String?

public let listPluralName: String?
public let syncPluralName: String?
public let authRules: AuthRules
public let fields: ModelFields
public let attributes: [ModelAttribute]
Expand All @@ -91,11 +96,15 @@ public struct ModelSchema {

public init(name: String,
pluralName: String? = nil,
listPluralName: String? = nil,
syncPluralName: String? = nil,
authRules: AuthRules = [],
attributes: [ModelAttribute] = [],
fields: ModelFields = [:]) {
self.name = name
self.pluralName = pluralName
self.listPluralName = listPluralName
self.syncPluralName = syncPluralName
self.authRules = authRules
self.attributes = attributes
self.fields = fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ extension MutationEvent {
public static let schema = defineSchema { definition in
let mutation = MutationEvent.keys

definition.pluralName = "MutationEvents"
definition.listPluralName = "MutationEvents"
definition.syncPluralName = "MutationEvents"
definition.attributes(.isSystem)

definition.fields(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ extension ModelSchema {
let graphQLName: String
switch queryType {
case .list:
graphQLName = (queryType.rawValue + name).pluralize()
if let listPluralName = listPluralName {
graphQLName = queryType.rawValue + listPluralName
} else {
graphQLName = (queryType.rawValue + name).pluralize()
}
case .sync:
if let pluralName = pluralName {
if let syncPluralName = syncPluralName {
graphQLName = queryType.rawValue + syncPluralName
} else if let pluralName = pluralName {
graphQLName = queryType.rawValue + pluralName
} else {
graphQLName = (queryType.rawValue + name).pluralize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ public struct MutationSync<ModelType: Model>: Decodable {
case let .number(lastChangedAt) = json["_lastChangedAt"],
case let .number(version) = json["_version"] else {

// TODO query name could be useful for the message, but re-creating it here is not great
let queryName = "sync\(modelType.schema.pluralName ?? modelType.modelName)"
throw DataStoreError.decodingError(
// TODO query name could be useful for the message, but re-creating it here is not great
let queryName = "sync\(modelType.schema.syncPluralName ?? modelType.schema.pluralName ?? modelType.modelName)"
throw DataStoreError.decodingError(
"""
Error decoding the the sync metadata from the delta sync query result.
""",
"""
The sync metadata should contain fields named `_deleted`, `_lastChangedAt` and `_version`.
Check your `\(queryName)` query and make sure it returns the correct set of sync fields.
"""
)
}
)
}

self.syncMetadata = MutationSyncMetadata(id: model.id,
deleted: deleted,
Expand Down
34 changes: 17 additions & 17 deletions AmplifyPlugins/DataStore/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ PODS:
- AWSPluginsCore (= 1.14.0)
- AppSyncRealTimeClient (1.5.0):
- Starscream (~> 3.1.1)
- AWSAuthCore (2.26.0):
- AWSCore (= 2.26.0)
- AWSCognitoIdentityProvider (2.26.0):
- AWSCognitoIdentityProviderASF (= 2.26.0)
- AWSCore (= 2.26.0)
- AWSCognitoIdentityProviderASF (2.26.0)
- AWSCore (2.26.0)
- AWSMobileClient (2.26.0):
- AWSAuthCore (= 2.26.0)
- AWSCognitoIdentityProvider (= 2.26.0)
- AWSCognitoIdentityProviderASF (= 2.26.0)
- AWSCore (= 2.26.0)
- AWSAuthCore (2.26.1):
- AWSCore (= 2.26.1)
- AWSCognitoIdentityProvider (2.26.1):
- AWSCognitoIdentityProviderASF (= 2.26.1)
- AWSCore (= 2.26.1)
- AWSCognitoIdentityProviderASF (2.26.1)
- AWSCore (2.26.1)
- AWSMobileClient (2.26.1):
- AWSAuthCore (= 2.26.1)
- AWSCognitoIdentityProvider (= 2.26.1)
- AWSCognitoIdentityProviderASF (= 2.26.1)
- AWSCore (= 2.26.1)
- AWSPluginsCore (1.14.0):
- Amplify (= 1.14.0)
- AWSCore (~> 2.26.0)
Expand Down Expand Up @@ -103,11 +103,11 @@ SPEC CHECKSUMS:
AmplifyPlugins: 94bb3e7e006b41f82e8a0a1dbbc48925d9edbe4c
AmplifyTestCommon: cf9d5a7a3bb697f8cd5fe4d8fae0f968033abdd0
AppSyncRealTimeClient: 2b4482b1770a3e5cf64f9714a6d198550017b5a2
AWSAuthCore: e33e7d1c2a7e6c08a026865f9396b0ef870faac3
AWSCognitoIdentityProvider: 4119e1492b23fc408a18c6dafe06888ef03c96e3
AWSCognitoIdentityProviderASF: a7f1e8cbafbac53ea1150ca50eac870d5c04dacf
AWSCore: b6d8dda67f24c6fc4c354334ec6d34238f37b735
AWSMobileClient: a9a498884df72531e3e73c9d7bb087f72364204d
AWSAuthCore: 264faaa6af5990af2c77effe8f398a4b80e6c44e
AWSCognitoIdentityProvider: 5df455775b57eb4e61862acd88d93e56113950c4
AWSCognitoIdentityProviderASF: b2c180f69537d57ff485f7314fd266032ca3f898
AWSCore: 0f855e20ccb13e028932b737f0706023a9561399
AWSMobileClient: ba255030a481b8a123b21585548e761456efc64b
AWSPluginsCore: 75950cfd39535b0a3654096cb472a7ee5b2ce0fa
CwlCatchException: 70a52ae44ea5d46db7bd385f801a94942420cd8c
CwlPreconditionTesting: d33a4e4f285c0b885fddcae5dfedfbb34d4f3961
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/Article+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ extension Article {
public static let schema = defineSchema { model in
let article = Article.keys

model.pluralName = "Articles"
model.listPluralName = "Articles"
model.syncPluralName = "Articles"

model.authRules = [
rule(allow: .owner, ownerField: "owner", operations: [.create, .read]),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/Collection/1/Project1+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extension Project1 {
public static let schema = defineSchema { model in
let project1 = Project1.keys

model.pluralName = "Project1s"
model.listPluralName = "Project1s"
model.syncPluralName = "Project1s"

model.fields(
.id(),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/Collection/1/Team1+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ extension Team1 {
public static let schema = defineSchema { model in
let team1 = Team1.keys

model.pluralName = "Team1s"
model.listPluralName = "Team1s"
model.syncPluralName = "Team1s"

model.fields(
.id(),
Expand Down
5 changes: 3 additions & 2 deletions AmplifyTestCommon/Models/Comment+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ extension Comment {

public static let schema = defineSchema { model in
let comment = Comment.keys

model.pluralName = "Comments"

model.listPluralName = "Comments"
model.syncPluralName = "Comments"

model.fields(
.id(),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/OGCScenarioBMGroupPost+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ extension OGCScenarioBMGroupPost {
rule(allow: .groups, groupClaim: "cognito:groups", groups: ["Admins", "HR"], operations: [.create, .update, .delete, .read])
]

model.pluralName = "OGCScenarioBMGroupPosts"
model.listPluralName = "OGCScenarioBMGroupPosts"
model.syncPluralName = "OGCScenarioBMGroupPosts"

model.fields(
.id(),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/OGCScenarioBPost+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ extension OGCScenarioBPost {
rule(allow: .groups, groupClaim: "cognito:groups", groups: ["Admins"], operations: [.create, .update, .delete, .read])
]

model.pluralName = "OGCScenarioBPosts"
model.listPluralName = "OGCScenarioBPosts"
model.syncPluralName = "OGCScenarioBPosts"

model.fields(
.id(),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/Post+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ extension Post {
public static let schema = defineSchema { model in
let post = Post.keys

model.pluralName = "Posts"
model.listPluralName = "Posts"
model.syncPluralName = "Posts"

model.fields(
.id(),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/QPredGen+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ extension QPredGen {
public static let schema = defineSchema { model in
let qPredGen = QPredGen.keys

model.pluralName = "QPredGens"
model.listPluralName = "QPredGens"
model.syncPluralName = "QPredGens"

model.fields(
.id(),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/Record+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ extension Record {
public static let schema = defineSchema { model in
let record = Record.keys

model.pluralName = "Records"
model.listPluralName = "Records"
model.listPluralName = "Records"

model.fields(
.id(),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/RecordCover+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ extension RecordCover {
public static let schema = defineSchema { model in
let recordCover = RecordCover.keys

model.pluralName = "RecordCovers"
model.listPluralName = "RecordCovers"
model.syncPluralName = "RecordCovers"

model.fields(
.id(),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/ScenarioATest6Post+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ extension ScenarioATest6Post {
rule(allow: .owner, ownerField: "owner", identityClaim: "sub", operations: [.create, .update, .delete, .read])
]

model.pluralName = "ScenarioATest6Posts"
model.listPluralName = "ScenarioATest6Posts"
model.syncPluralName = "ScenarioATest6Posts"

model.fields(
.id(),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/User+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ extension User {
public static let schema = defineSchema { model in
let user = User.keys

model.pluralName = "Users"
model.listPluralName = "Users"
model.syncPluralName = "Users"

model.fields(
.id(),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/UserFollowers+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extension UserFollowers {
public static let schema = defineSchema { model in
let userFollowers = UserFollowers.keys

model.pluralName = "UserFollowers"
model.listPluralName = "UserFollowers"
model.SyncPluralName = "UserFollowers"

model.fields(
.id(),
Expand Down
3 changes: 2 additions & 1 deletion AmplifyTestCommon/Models/UserFollowing+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extension UserFollowing {
public static let schema = defineSchema { model in
let userFollowing = UserFollowing.keys

model.pluralName = "UserFollowings"
model.listPluralName = "UserFollowings"
model.syncPluralName = "UserFollowings"

model.fields(
.id(),
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- AWSCore (2.26.0)
- AWSCore (2.26.1)
- CwlCatchException (1.0.2)
- CwlPreconditionTesting (1.1.1):
- CwlCatchException
Expand Down Expand Up @@ -36,7 +36,7 @@ CHECKOUT OPTIONS:
:tag: 1.2.0

SPEC CHECKSUMS:
AWSCore: b6d8dda67f24c6fc4c354334ec6d34238f37b735
AWSCore: 0f855e20ccb13e028932b737f0706023a9561399
CwlCatchException: 70a52ae44ea5d46db7bd385f801a94942420cd8c
CwlPreconditionTesting: d33a4e4f285c0b885fddcae5dfedfbb34d4f3961
SwiftFormat: 3b5caa6389b2b9adbc00e133b3ccc8c6e687a6a4
Expand Down

0 comments on commit db3e03a

Please sign in to comment.