Skip to content

Commit d3ba16a

Browse files
authored
fix: Adding back customType with deprecated message (#562)
* Adding back customType with deprecated message * added deprecated example * remove Podfile.lock changes * revert Manifest.lock
1 parent 51caeab commit d3ba16a

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-1
lines changed

Amplify.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
21A3FDB62464590600E76120 /* ModelMultipleOwnerAuthRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A3FDB52464590600E76120 /* ModelMultipleOwnerAuthRuleTests.swift */; };
112112
21A3FDB9246494CD00E76120 /* GraphQLRequestAuthRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A3FDB8246494CD00E76120 /* GraphQLRequestAuthRuleTests.swift */; };
113113
21A3FDBF2465FA1500E76120 /* AuthRule+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A3FDBE2465FA1500E76120 /* AuthRule+Extension.swift */; };
114+
21AD4257249BFFE00016FE95 /* DeprecatedTodo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AD4255249BFFDF0016FE95 /* DeprecatedTodo.swift */; };
114115
21C395B3245729EC00597EA2 /* AppSyncErrorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21C395B2245729EC00597EA2 /* AppSyncErrorType.swift */; };
115116
21D79FDA237617C60057D00D /* SubscriptionEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D79FD9237617C60057D00D /* SubscriptionEvent.swift */; };
116117
21D79FE32377F4120057D00D /* SubscriptionConnectionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D79FE22377F4120057D00D /* SubscriptionConnectionState.swift */; };
@@ -757,6 +758,7 @@
757758
21A3FDB52464590600E76120 /* ModelMultipleOwnerAuthRuleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMultipleOwnerAuthRuleTests.swift; sourceTree = "<group>"; };
758759
21A3FDB8246494CD00E76120 /* GraphQLRequestAuthRuleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLRequestAuthRuleTests.swift; sourceTree = "<group>"; };
759760
21A3FDBE2465FA1500E76120 /* AuthRule+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AuthRule+Extension.swift"; sourceTree = "<group>"; };
761+
21AD4255249BFFDF0016FE95 /* DeprecatedTodo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DeprecatedTodo.swift; path = Deprecated/DeprecatedTodo.swift; sourceTree = "<group>"; };
760762
21C395B2245729EC00597EA2 /* AppSyncErrorType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSyncErrorType.swift; sourceTree = "<group>"; };
761763
21D79FD9237617C60057D00D /* SubscriptionEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionEvent.swift; sourceTree = "<group>"; };
762764
21D79FE22377F4120057D00D /* SubscriptionConnectionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionConnectionState.swift; sourceTree = "<group>"; };
@@ -2228,6 +2230,7 @@
22282230
B952182D237E21B900F53237 /* Models */ = {
22292231
isa = PBXGroup;
22302232
children = (
2233+
21AD4255249BFFDF0016FE95 /* DeprecatedTodo.swift */,
22312234
216E45E9248E91420035E3CE /* NonModel */,
22322235
FAF512AD23986791001ADF4E /* AmplifyModels.swift */,
22332236
214F49CB24898E8400DA616C /* Article.swift */,
@@ -4489,6 +4492,7 @@
44894492
21F40A4023A295470074678E /* TestCommonConstants.swift in Sources */,
44904493
214F497C2486D8A200DA616C /* UserFollowers.swift in Sources */,
44914494
B9521835237E21BA00F53237 /* Comment.swift in Sources */,
4495+
21AD4257249BFFE00016FE95 /* DeprecatedTodo.swift in Sources */,
44924496
216E45EF248E914F0035E3CE /* Todo+Schema.swift in Sources */,
44934497
FACA361E2327FC8E000E74F6 /* MockAnalyticsCategoryPlugin.swift in Sources */,
44944498
2129BE012394627B006363A1 /* PostCommentModelRegistration.swift in Sources */,

Amplify/Categories/DataStore/Model/Embedded.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Foundation
1212
/// A `Embeddable` type can be used in a `Model` as an embedded type. All types embedded in a `Model` as an
1313
/// `embedded(type:)` or `embeddedCollection(of:)` must comform to the `Embeddable` protocol except for Swift's Basic
1414
/// types embedded as a collection. A collection of String can be embedded in the `Model` as
15-
/// `embeddedCollection(of: String.self)` without needing to conform to Embeddable.
15+
/// `embeddedCollection(of: String.self)` without needing to conform to Embeddable.
1616
public protocol Embeddable: Codable {
1717

1818
/// A reference to the `ModelSchema` associated with this embedded type.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public enum ModelFieldType {
3333
}
3434
}
3535

36+
@available(*, deprecated, message: """
37+
This has been replaced with `.embedded(type)` and `.embeddedCollection(of)` \
38+
Please use Amplify CLI 4.21.4 or newer to re-generate your Models to conform to Embeddable type.
39+
""")
40+
public static func customType(_ type: Codable.Type) -> ModelFieldType {
41+
return .embedded(type: type)
42+
}
43+
3644
public static func from(type: Any.Type) -> ModelFieldType {
3745
if type is String.Type {
3846
return .string
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// Copyright 2018-2020 Amazon.com,
3+
// Inc. or its affiliates. All Rights Reserved.
4+
//
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
8+
// swiftlint:disable all
9+
import Amplify
10+
import Foundation
11+
/*
12+
The schema used to codegen this model:
13+
type DeprecatedTodo @model {
14+
id: ID!
15+
description: String
16+
note: Note
17+
}
18+
type Note {
19+
name: String!
20+
color: String!
21+
}
22+
23+
Amplify CLI version used is less than 4.21.4. `.customType` has since been replaced with `.embedded(type)` and
24+
`.embeddedCollection(of)`. Please use Amplify CLI 4.21.4 or newer to re-generate your Models to conform to
25+
Embeddable type.
26+
*/
27+
28+
public struct DeprecatedTodo: Model {
29+
public let id: String
30+
public var description: String?
31+
public var note: Note?
32+
33+
public init(id: String = UUID().uuidString,
34+
description: String? = nil,
35+
note: Note? = nil) {
36+
self.id = id
37+
self.description = description
38+
self.note = note
39+
}
40+
}
41+
42+
extension DeprecatedTodo {
43+
// MARK: - CodingKeys
44+
public enum CodingKeys: String, ModelKey {
45+
case id
46+
case description
47+
case note
48+
}
49+
50+
public static let keys = CodingKeys.self
51+
// MARK: - ModelSchema
52+
53+
public static let schema = defineSchema { model in
54+
let deprecatedTodo = DeprecatedTodo.keys
55+
56+
model.pluralName = "DeprecatedTodos"
57+
58+
model.fields(
59+
.id(),
60+
.field(deprecatedTodo.description, is: .optional, ofType: .string),
61+
.field(deprecatedTodo.note, is: .optional, ofType: .customType(Note.self))
62+
)
63+
}
64+
}
65+
66+
public struct Note: Codable {
67+
var name: String
68+
var color: String
69+
}

0 commit comments

Comments
 (0)