Skip to content

Commit 944976f

Browse files
authored
Revert "fix(amplify): DataStore query fix column missing issue for @connection hasMany schema (#885)" (#963)
This reverts commit 028a707. Co-authored-by: Guo <[email protected]>
1 parent a675426 commit 944976f

File tree

19 files changed

+261
-363
lines changed

19 files changed

+261
-363
lines changed

Amplify.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@
452452
B9FAA180238FBB5D009414B4 /* Model+Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9FAA17F238FBB5D009414B4 /* Model+Array.swift */; };
453453
B9FB05F82383740D00DE1FD4 /* DataStoreStatement.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9FB05F72383740D00DE1FD4 /* DataStoreStatement.swift */; };
454454
D83C5160248964780091548E /* ModelGraphQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D83C515F248964780091548E /* ModelGraphQLTests.swift */; };
455-
D84CF107255C5CA8007B96A9 /* CodingKeysTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84CF106255C5CA8007B96A9 /* CodingKeysTests.swift */; };
456455
D8DD7A1D24A1CCCD001C49FD /* QuerySortInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8DD7A1C24A1CCCD001C49FD /* QuerySortInput.swift */; };
457456
FA00F68824DA37EE003E8A71 /* AuthCategoryBehavior+Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA00F68724DA37EE003E8A71 /* AuthCategoryBehavior+Combine.swift */; };
458457
FA00F68A24DA3A43003E8A71 /* AuthCategoryDeviceBehavior+Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA00F68924DA3A43003E8A71 /* AuthCategoryDeviceBehavior+Combine.swift */; };
@@ -1340,7 +1339,6 @@
13401339
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; };
13411340
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 = "<group>"; };
13421341
D83C515F248964780091548E /* ModelGraphQLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelGraphQLTests.swift; sourceTree = "<group>"; };
1343-
D84CF106255C5CA8007B96A9 /* CodingKeysTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodingKeysTests.swift; sourceTree = "<group>"; };
13441342
D8DD7A1C24A1CCCD001C49FD /* QuerySortInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuerySortInput.swift; sourceTree = "<group>"; };
13451343
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 = "<group>"; };
13461344
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 = "<group>"; };
@@ -3565,7 +3563,6 @@
35653563
FAD3937B23820CE200463F5E /* DataStore */ = {
35663564
isa = PBXGroup;
35673565
children = (
3568-
D84CF106255C5CA8007B96A9 /* CodingKeysTests.swift */,
35693566
FAD3937923820CDB00463F5E /* DataStoreCategoryClientAPITests.swift */,
35703567
FAD3937C23820D0200463F5E /* DataStoreCategoryConfigurationTests.swift */,
35713568
B4944D51251C141200BF0BFE /* JSONValueHolderTest.swift */,
@@ -5001,7 +4998,6 @@
50014998
B91A87A423D64B0F0049A12F /* TemporalTests.swift in Sources */,
50024999
FA00F69024DA3F95003E8A71 /* HubCombineTests.swift in Sources */,
50035000
FA5D76AF23947E9C00489864 /* Model+CodableTests.swift in Sources */,
5004-
D84CF107255C5CA8007B96A9 /* CodingKeysTests.swift in Sources */,
50055001
FA58456B24DA31370028D65A /* AmplifyInProcessReportingOperationChainedTests.swift in Sources */,
50065002
FA1B964E24BF5FA70002B90A /* AmplifyOperationCombineTests.swift in Sources */,
50075003
FAAFAF3323904BA4002CF932 /* AtomicValue+NumericTests.swift in Sources */,

Amplify/Categories/DataStore/Query/ModelKey.swift

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,24 @@ import Foundation
3232
/// post.content != nil
3333
/// })
3434
/// ```
35-
public protocol ModelKey: CodingKey, CaseIterable, QueryFieldOperation, DefaultLogger {
36-
var modelName: String { get }
37-
}
38-
39-
extension ModelKey {
40-
public var modelName: String { "" }
41-
}
35+
public protocol ModelKey: CodingKey, CaseIterable, QueryFieldOperation {}
4236

4337
extension CodingKey where Self: ModelKey {
4438

45-
var columnName: String {
46-
guard let modelSchema: ModelSchema = ModelRegistry.modelSchema(from: modelName) else {
47-
log.warn("Please upgrade to the latest version of Amplify CLI and rerun `amplify codegen models`")
48-
return stringValue
49-
}
50-
switch modelSchema.field(withName: stringValue)?.association {
51-
case .belongsTo(_, let targetName):
52-
return targetName ?? stringValue
53-
default:
54-
return stringValue
55-
}
56-
}
57-
5839
// MARK: - beginsWith
5940
public func beginsWith(_ value: String) -> QueryPredicateOperation {
60-
return field(columnName).beginsWith(value)
41+
return field(stringValue).beginsWith(value)
6142
}
6243

6344
// MARK: - between
6445
public func between(start: Persistable, end: Persistable) -> QueryPredicateOperation {
65-
return field(columnName).between(start: start, end: end)
46+
return field(stringValue).between(start: start, end: end)
6647
}
6748

6849
// MARK: - contains
6950

7051
public func contains(_ value: String) -> QueryPredicateOperation {
71-
return field(columnName).contains(value)
52+
return field(stringValue).contains(value)
7253
}
7354

7455
public static func ~= (key: Self, value: String) -> QueryPredicateOperation {
@@ -78,11 +59,11 @@ extension CodingKey where Self: ModelKey {
7859
// MARK: - eq
7960

8061
public func eq(_ value: Persistable?) -> QueryPredicateOperation {
81-
return field(columnName).eq(value)
62+
return field(stringValue).eq(value)
8263
}
8364

8465
public func eq(_ value: EnumPersistable) -> QueryPredicateOperation {
85-
return field(columnName).eq(value)
66+
return field(stringValue).eq(value)
8667
}
8768

8869
public static func == (key: Self, value: Persistable?) -> QueryPredicateOperation {
@@ -96,7 +77,7 @@ extension CodingKey where Self: ModelKey {
9677
// MARK: - ge
9778

9879
public func ge(_ value: Persistable) -> QueryPredicateOperation {
99-
return field(columnName).ge(value)
80+
return field(stringValue).ge(value)
10081
}
10182

10283
public static func >= (key: Self, value: Persistable) -> QueryPredicateOperation {
@@ -106,7 +87,7 @@ extension CodingKey where Self: ModelKey {
10687
// MARK: - gt
10788

10889
public func gt(_ value: Persistable) -> QueryPredicateOperation {
109-
return field(columnName).gt(value)
90+
return field(stringValue).gt(value)
11091
}
11192

11293
public static func > (key: Self, value: Persistable) -> QueryPredicateOperation {
@@ -116,7 +97,7 @@ extension CodingKey where Self: ModelKey {
11697
// MARK: - le
11798

11899
public func le(_ value: Persistable) -> QueryPredicateOperation {
119-
return field(columnName).le(value)
100+
return field(stringValue).le(value)
120101
}
121102

122103
public static func <= (key: Self, value: Persistable) -> QueryPredicateOperation {
@@ -126,7 +107,7 @@ extension CodingKey where Self: ModelKey {
126107
// MARK: - lt
127108

128109
public func lt(_ value: Persistable) -> QueryPredicateOperation {
129-
return field(columnName).lt(value)
110+
return field(stringValue).lt(value)
130111
}
131112

132113
public static func < (key: Self, value: Persistable) -> QueryPredicateOperation {
@@ -136,11 +117,11 @@ extension CodingKey where Self: ModelKey {
136117
// MARK: - ne
137118

138119
public func ne(_ value: Persistable?) -> QueryPredicateOperation {
139-
return field(columnName).ne(value)
120+
return field(stringValue).ne(value)
140121
}
141122

142123
public func ne(_ value: EnumPersistable) -> QueryPredicateOperation {
143-
return field(columnName).ne(value)
124+
return field(stringValue).ne(value)
144125
}
145126

146127
public static func != (key: Self, value: Persistable?) -> QueryPredicateOperation {

AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/AuthRuleDecorator/ModelWithOwnerAuthAndGroupWithGroupClaim.swift

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ import XCTest
1616
@model
1717
@auth(
1818
rules: [
19-
{ allow: owner, provider: oidc, identityClaim: "sub" }
20-
{
21-
allow: groups
22-
provider: oidc
23-
groups: ["Admins"]
24-
groupClaim: "https://myapp.com/claims/groups"
25-
}
19+
{ allow: owner, provider: oidc, identityClaim: "sub"},
20+
{ allow: groups, provider: oidc, groups: ["Admins"],
21+
groupClaim: "https://myapp.com/claims/groups"}
2622
]
2723
) {
2824
id: ID!
@@ -32,48 +28,48 @@ import XCTest
3228
*/
3329

3430
public struct OIDCGroupPost: Model {
35-
public let id: String
36-
public var title: String
37-
public var owner: String?
38-
39-
public init(id: String = UUID().uuidString,
40-
title: String,
41-
owner: String? = nil) {
42-
self.id = id
43-
self.title = title
44-
self.owner = owner
45-
}
31+
public let id: String
32+
public var title: String
33+
public var owner: String?
34+
35+
public init(id: String = UUID().uuidString,
36+
title: String,
37+
owner: String? = nil) {
38+
self.id = id
39+
self.title = title
40+
self.owner = owner
41+
}
4642

4743
// MARK: - CodingKeys
48-
public enum CodingKeys: String, ModelKey {
49-
case id
50-
case title
51-
case owner
44+
public enum CodingKeys: String, ModelKey {
45+
case id
46+
case title
47+
case owner
5248
}
5349

5450
public static let keys = CodingKeys.self
5551
public static let schema = defineSchema { model in
56-
let oIDCGroupPost = OIDCGroupPost.keys
57-
58-
model.authRules = [
59-
rule(allow: .owner,
60-
ownerField: "owner",
61-
identityClaim: "sub",
62-
operations: [.create, .update, .delete, .read]),
63-
rule(allow: .groups,
64-
groupClaim: "https://myapp.com/claims/groups",
65-
groups: ["Admins"],
66-
operations: [.create, .update, .delete, .read])
67-
]
68-
69-
model.pluralName = "OIDCGroupPosts"
70-
71-
model.fields(
72-
.id(),
73-
.field(oIDCGroupPost.title, is: .required, ofType: .string),
74-
.field(oIDCGroupPost.owner, is: .optional, ofType: .string)
75-
)
76-
}
52+
let oIDCGroupPost = OIDCGroupPost.keys
53+
54+
model.authRules = [
55+
rule(allow: .owner,
56+
ownerField: "owner",
57+
identityClaim: "sub",
58+
operations: [.create, .update, .delete, .read]),
59+
rule(allow: .groups,
60+
groupClaim: "https://myapp.com/claims/groups",
61+
groups: ["Admins"],
62+
operations: [.create, .update, .delete, .read])
63+
]
64+
65+
model.pluralName = "OIDCGroupPosts"
66+
67+
model.fields(
68+
.id(),
69+
.field(oIDCGroupPost.title, is: .required, ofType: .string),
70+
.field(oIDCGroupPost.owner, is: .optional, ofType: .string)
71+
)
72+
}
7773
}
7874

7975
class ModelWithOwnerAuthAndGroupWithGroupClaim: XCTestCase {

AmplifyPlugins/Core/AWSPluginsTestCommon/MockAWSAuthService.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class MockAWSAuthService: AWSAuthServiceBehavior {
1616
var getTokenClaimsError: AuthError?
1717
var identityId: String?
1818
var token: String?
19-
var tokenClaims: [String: AnyObject]?
19+
var tokenClaims: [String : AnyObject]?
2020

2121
public func configure() {
2222
}
@@ -45,10 +45,10 @@ public class MockAWSAuthService: AWSAuthServiceBehavior {
4545
return .success(token ?? "token")
4646
}
4747

48-
public func getTokenClaims(tokenString: String) -> Result<[String: AnyObject], AuthError> {
48+
public func getTokenClaims(tokenString: String) -> Result<[String : AnyObject], AuthError> {
4949
if let error = getTokenClaimsError {
5050
return .failure(error)
5151
}
52-
return .success(tokenClaims ?? ["": "" as AnyObject])
52+
return .success(tokenClaims ?? ["":"" as AnyObject])
5353
}
5454
}

AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Core/SQLStatementTests.swift

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -330,31 +330,6 @@ class SQLStatementTests: XCTestCase {
330330
XCTAssertEqual(statement.stringValue, expectedStatement)
331331
}
332332

333-
/// - Given: a `Model` type
334-
/// - When:
335-
/// - the model is of type `Comment`
336-
/// - `QueryPredicate` on a connected field is given
337-
/// - Then:
338-
/// - check if the generated SQL statement is valid
339-
/// - check if an inner join is added referencing `Post`
340-
/// - check if a where with columnName `commentPostId` is generated
341-
func testSelectStatementFromModelWhenQueryPredicateIsGiven() {
342-
let statement = SelectStatement(from: Comment.schema, predicate: Comment.keys.post == "commentPostId")
343-
let expectedStatement = """
344-
select
345-
"root"."id" as "id", "root"."content" as "content", "root"."createdAt" as "createdAt",
346-
"root"."commentPostId" as "commentPostId", "post"."id" as "post.id", "post"."content" as "post.content",
347-
"post"."createdAt" as "post.createdAt", "post"."draft" as "post.draft", "post"."rating" as "post.rating",
348-
"post"."status" as "post.status", "post"."title" as "post.title", "post"."updatedAt" as "post.updatedAt"
349-
from Comment as "root"
350-
inner join Post as "post"
351-
on "post"."id" = "root"."commentPostId"
352-
where 1 = 1
353-
and "root"."commentPostId" = ?
354-
"""
355-
XCTAssertEqual(statement.stringValue, expectedStatement)
356-
}
357-
358333
// MARK: - Select Statements paginated
359334

360335
/// - Given: a `Model` type and a `QueryPaginationInput`

AmplifyTestCommon/Models/Associations/BookAuthor+Schema.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ extension BookAuthor {
1515
case id
1616
case book
1717
case author
18-
19-
public var modelName: String {
20-
return "BookAuthor"
21-
}
2218
}
2319

2420
public static let keys = CodingKeys.self

AmplifyTestCommon/Models/Associations/UserProfile+Schema.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ extension UserProfile {
1414
public enum CodingKeys: String, ModelKey {
1515
case id
1616
case account
17-
18-
public var modelName: String {
19-
return "UserProfile"
20-
}
2117
}
2218

2319
public static let keys = CodingKeys.self

AmplifyTestCommon/Models/Comment+Schema.swift

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,27 @@ import Amplify
1010
import Foundation
1111

1212
extension Comment {
13-
// MARK: - CodingKeys
14-
public enum CodingKeys: String, ModelKey {
15-
case id
16-
case content
17-
case createdAt
18-
case post
13+
// MARK: - CodingKeys
14+
public enum CodingKeys: String, ModelKey {
15+
case id
16+
case content
17+
case createdAt
18+
case post
19+
}
1920

20-
public var modelName: String {
21-
return "Comment"
22-
}
23-
}
24-
25-
public static let keys = CodingKeys.self
26-
// MARK: - ModelSchema
21+
public static let keys = CodingKeys.self
22+
// MARK: - ModelSchema
2723

28-
public static let schema = defineSchema { model in
29-
let comment = Comment.keys
24+
public static let schema = defineSchema { model in
25+
let comment = Comment.keys
3026

31-
model.pluralName = "Comments"
27+
model.pluralName = "Comments"
3228

33-
model.fields(
34-
.id(),
35-
.field(comment.content, is: .required, ofType: .string),
36-
.field(comment.createdAt, is: .required, ofType: .dateTime),
37-
.belongsTo(comment.post, is: .required, ofType: Post.self, targetName: "commentPostId")
38-
)
29+
model.fields(
30+
.id(),
31+
.field(comment.content, is: .required, ofType: .string),
32+
.field(comment.createdAt, is: .required, ofType: .dateTime),
33+
.belongsTo(comment.post, is: .required, ofType: Post.self, targetName: "commentPostId")
34+
)
3935
}
4036
}

0 commit comments

Comments
 (0)