Skip to content

Commit 2aaaf2c

Browse files
authored
fix: Support new list name pluralization (#1451)
* fix: Support new list name pluralization * update rest of the schema files * update rest of the schema files (API and DataStore) * add unit test
1 parent a1d1661 commit 2aaaf2c

File tree

88 files changed

+282
-106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+282
-106
lines changed

Amplify.xcodeproj/project.pbxproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@
175175
21C395B3245729EC00597EA2 /* AppSyncErrorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21C395B2245729EC00597EA2 /* AppSyncErrorType.swift */; };
176176
21D79FDA237617C60057D00D /* SubscriptionEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D79FD9237617C60057D00D /* SubscriptionEvent.swift */; };
177177
21D79FE32377F4120057D00D /* SubscriptionConnectionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D79FE22377F4120057D00D /* SubscriptionConnectionState.swift */; };
178+
21DDCDF7272C3D7400D9B297 /* ModelSchemaGraphQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21DDCDF5272C3D6A00D9B297 /* ModelSchemaGraphQLTests.swift */; };
179+
21DDCDF8272C3D8300D9B297 /* AuthRuleExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 762F70A326683EE2001F8252 /* AuthRuleExtensionTests.swift */; };
178180
21F40A3A23A294770074678E /* TestConfigHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21F40A3923A294770074678E /* TestConfigHelper.swift */; };
179181
21F40A4023A295470074678E /* TestCommonConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21F40A3F23A295470074678E /* TestCommonConstants.swift */; };
180182
21FDBB612587D7A30086FCDC /* Blog6.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21FDBB5B2587D7A30086FCDC /* Blog6.swift */; };
@@ -250,7 +252,6 @@
250252
762167D52615435C0033FCD2 /* Record+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 762167D42615435C0033FCD2 /* Record+Schema.swift */; };
251253
762C978526210F6400798FA3 /* RecordCover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 762C978426210F6400798FA3 /* RecordCover.swift */; };
252254
762C978E26210FF100798FA3 /* RecordCover+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 762C978D26210FF100798FA3 /* RecordCover+Schema.swift */; };
253-
762F70A426683EE2001F8252 /* AuthRuleExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 762F70A326683EE2001F8252 /* AuthRuleExtensionTests.swift */; };
254255
7638895326A7A9AC0061AF0B /* AWSLambdaAuthConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7638895226A7A9AC0061AF0B /* AWSLambdaAuthConfiguration.swift */; };
255256
7678B38426017D5300B4917F /* AppSyncErrorTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7678B38326017D5300B4917F /* AppSyncErrorTypeTests.swift */; };
256257
7678B38526017D5300B4917F /* AppSyncErrorTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7678B38326017D5300B4917F /* AppSyncErrorTypeTests.swift */; };
@@ -1013,6 +1014,7 @@
10131014
21C395B2245729EC00597EA2 /* AppSyncErrorType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSyncErrorType.swift; sourceTree = "<group>"; };
10141015
21D79FD9237617C60057D00D /* SubscriptionEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionEvent.swift; sourceTree = "<group>"; };
10151016
21D79FE22377F4120057D00D /* SubscriptionConnectionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionConnectionState.swift; sourceTree = "<group>"; };
1017+
21DDCDF5272C3D6A00D9B297 /* ModelSchemaGraphQLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelSchemaGraphQLTests.swift; sourceTree = "<group>"; };
10161018
21F40A3923A294770074678E /* TestConfigHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestConfigHelper.swift; sourceTree = "<group>"; };
10171019
21F40A3F23A295470074678E /* TestCommonConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCommonConstants.swift; sourceTree = "<group>"; };
10181020
21FDBB5B2587D7A30086FCDC /* Blog6.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Blog6.swift; sourceTree = "<group>"; };
@@ -1917,6 +1919,7 @@
19171919
2129BE2F2394828A006363A1 /* QueryPredicateGraphQLTests.swift */,
19181920
D83C515F248964780091548E /* ModelGraphQLTests.swift */,
19191921
762F70A326683EE2001F8252 /* AuthRuleExtensionTests.swift */,
1922+
21DDCDF5272C3D6A00D9B297 /* ModelSchemaGraphQLTests.swift */,
19201923
);
19211924
path = Support;
19221925
sourceTree = "<group>";
@@ -4869,6 +4872,7 @@
48694872
219A888723EB89C200BBC5F2 /* GraphQLRequestAnyModelWithSyncTests.swift in Sources */,
48704873
2183A56423EA4A7F00232880 /* GraphQLGetQueryTests.swift in Sources */,
48714874
6B5087C7256638EA000AB673 /* QueryPredicateEvaluateGeneratedDateTests.swift in Sources */,
4875+
21DDCDF8272C3D8300D9B297 /* AuthRuleExtensionTests.swift in Sources */,
48724876
6BBECD7423ADA9D100C8DFBE /* AmplifyAWSServiceConfigurationTests.swift in Sources */,
48734877
6BAF4F38256893B900A811BA /* QueryPredicateEvaluateGenerator.swift in Sources */,
48744878
6B9F7C5225267E1500F1F71C /* MockAWSAuthUser.swift in Sources */,
@@ -4882,6 +4886,7 @@
48824886
6B5087C3256630DB000AB673 /* QueryPredicateEvaluateGeneratedIntTests.swift in Sources */,
48834887
21AD425B249C0DBE0016FE95 /* AnyModelTests.swift in Sources */,
48844888
D83C5160248964780091548E /* ModelGraphQLTests.swift in Sources */,
4889+
21DDCDF7272C3D7400D9B297 /* ModelSchemaGraphQLTests.swift in Sources */,
48854890
);
48864891
runOnlyForDeploymentPostprocessing = 0;
48874892
};
@@ -5338,7 +5343,6 @@
53385343
FAC23564227A056600424678 /* StorageCategoryClientAPITests.swift in Sources */,
53395344
FAAFAF3123904B75002CF932 /* AtomicValue+BoolTests.swift in Sources */,
53405345
B9AF547E23F37DF20059E6C4 /* TemporalOperationTests.swift in Sources */,
5341-
762F70A426683EE2001F8252 /* AuthRuleExtensionTests.swift in Sources */,
53425346
FAD3937D23820D0200463F5E /* DataStoreCategoryConfigurationTests.swift in Sources */,
53435347
FA607FE2233D131B00DFEA24 /* AmplifyOperationHubTests.swift in Sources */,
53445348
B4944D52251C141200BF0BFE /* JSONValueHolderTest.swift in Sources */,

Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Definition.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,27 @@ public enum ModelFieldNullability {
124124
public struct ModelSchemaDefinition {
125125

126126
internal let name: String
127+
128+
@available(*, deprecated, message: "Use of pluralName is deprecated, use syncPluralName instead.")
127129
public var pluralName: String?
130+
131+
public var listPluralName: String?
132+
public var syncPluralName: String?
133+
128134
public var authRules: AuthRules
129135
internal var fields: ModelFields
130136
internal var attributes: [ModelAttribute]
131137

132138
init(name: String,
133139
pluralName: String? = nil,
140+
listPluralName: String? = nil,
141+
syncPluralName: String? = nil,
134142
authRules: AuthRules = [],
135143
attributes: [ModelAttribute] = []) {
136144
self.name = name
137145
self.pluralName = pluralName
146+
self.listPluralName = listPluralName
147+
self.syncPluralName = syncPluralName
138148
self.fields = [:] as ModelFields
139149
self.authRules = authRules
140150
self.attributes = attributes
@@ -154,6 +164,8 @@ public struct ModelSchemaDefinition {
154164
internal func build() -> ModelSchema {
155165
return ModelSchema(name: name,
156166
pluralName: pluralName,
167+
listPluralName: listPluralName,
168+
syncPluralName: syncPluralName,
157169
authRules: authRules,
158170
attributes: attributes,
159171
fields: fields)

Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ public typealias ModelName = String
7575
public struct ModelSchema {
7676

7777
public let name: String
78+
79+
@available(*, deprecated, message: "Use of pluralName is deprecated, use syncPluralName instead.")
7880
public let pluralName: String?
81+
82+
public let listPluralName: String?
83+
public let syncPluralName: String?
7984
public let authRules: AuthRules
8085
public let fields: ModelFields
8186
public let attributes: [ModelAttribute]
@@ -91,11 +96,15 @@ public struct ModelSchema {
9196

9297
public init(name: String,
9398
pluralName: String? = nil,
99+
listPluralName: String? = nil,
100+
syncPluralName: String? = nil,
94101
authRules: AuthRules = [],
95102
attributes: [ModelAttribute] = [],
96103
fields: ModelFields = [:]) {
97104
self.name = name
98105
self.pluralName = pluralName
106+
self.listPluralName = listPluralName
107+
self.syncPluralName = syncPluralName
99108
self.authRules = authRules
100109
self.attributes = attributes
101110
self.fields = fields

Amplify/Categories/DataStore/Subscribe/MutationEvent+Schema.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ extension MutationEvent {
2727
public static let schema = defineSchema { definition in
2828
let mutation = MutationEvent.keys
2929

30-
definition.pluralName = "MutationEvents"
30+
definition.listPluralName = "MutationEvents"
31+
definition.syncPluralName = "MutationEvents"
3132
definition.attributes(.isSystem)
3233

3334
definition.fields(

AmplifyPlugins/API/AWSAPICategoryPluginIntegrationTests/GraphQL/GraphQLWithIAMIntegrationTests/GraphQLWithIAMIntegrationTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ class GraphQLWithIAMIntegrationTests: XCTestCase {
303303
static let schema = defineSchema { model in
304304
let todo = Todo.keys
305305

306-
model.pluralName = "Todos"
306+
model.listPluralName = "Todos"
307+
model.syncPluralName = "Todos"
307308

308309
model.fields(
309310
.id(),

AmplifyPlugins/API/AWSAPICategoryPluginIntegrationTests/GraphQL/GraphQLWithLambdaAuthIntegrationTests/GraphQLWithLambdaAuthIntegrationTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ class GraphQLWithLambdaAuthIntegrationTests: XCTestCase {
224224
static let schema = defineSchema { model in
225225
let todo = Todo.keys
226226

227-
model.pluralName = "Todos"
227+
model.listPluralName = "Todos"
228+
model.syncPluralName = "Todos"
228229

229230
model.fields(
230231
.id(),

AmplifyPlugins/API/AWSAPICategoryPluginIntegrationTests/GraphQL/GraphQLWithUserPoolIntegrationTests/AuthDirective/SocialNote.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ extension SocialNote {
3939
rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", operations: [.create, .update, .delete])
4040
]
4141

42-
model.pluralName = "SocialNotes"
42+
model.listPluralName = "SocialNotes"
43+
model.syncPluralName = "SocialNotes"
4344

4445
model.fields(
4546
.id(),

AmplifyPlugins/API/AWSAPICategoryPluginTests/Support/Decode/GraphQLResponseDecoderTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class GraphQLResponseDecoderTests: XCTestCase {
4141

4242
static let schema = defineSchema { model in
4343
let post = Post.keys
44-
model.pluralName = "SimpleModels"
44+
model.listPluralName = "SimpleModels"
45+
model.syncPluralName = "SimpleModels"
4546
model.fields(
4647
.id()
4748
)

AmplifyPlugins/Core/AWSPluginsCore/Model/Support/ModelSchema+GraphQL.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ extension ModelSchema {
1616
let graphQLName: String
1717
switch queryType {
1818
case .list:
19-
graphQLName = (queryType.rawValue + name).pluralize()
19+
if let listPluralName = listPluralName {
20+
graphQLName = queryType.rawValue + listPluralName
21+
} else {
22+
graphQLName = (queryType.rawValue + name).pluralize()
23+
}
2024
case .sync:
21-
if let pluralName = pluralName {
25+
if let syncPluralName = syncPluralName {
26+
graphQLName = queryType.rawValue + syncPluralName
27+
} else if let pluralName = pluralName {
2228
graphQLName = queryType.rawValue + pluralName
2329
} else {
2430
graphQLName = (queryType.rawValue + name).pluralize()

AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSync.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ public struct MutationSync<ModelType: Model>: Decodable {
6161
case let .number(lastChangedAt) = json["_lastChangedAt"],
6262
case let .number(version) = json["_version"] else {
6363

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

7777
self.syncMetadata = MutationSyncMetadata(id: model.id,
7878
deleted: deleted,

0 commit comments

Comments
 (0)