Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adding back customType with deprecated message #562

Merged
merged 4 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Amplify.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
21A3FDB62464590600E76120 /* ModelMultipleOwnerAuthRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A3FDB52464590600E76120 /* ModelMultipleOwnerAuthRuleTests.swift */; };
21A3FDB9246494CD00E76120 /* GraphQLRequestAuthRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A3FDB8246494CD00E76120 /* GraphQLRequestAuthRuleTests.swift */; };
21A3FDBF2465FA1500E76120 /* AuthRule+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A3FDBE2465FA1500E76120 /* AuthRule+Extension.swift */; };
21AD4257249BFFE00016FE95 /* DeprecatedTodo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AD4255249BFFDF0016FE95 /* DeprecatedTodo.swift */; };
21C395B3245729EC00597EA2 /* AppSyncErrorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21C395B2245729EC00597EA2 /* AppSyncErrorType.swift */; };
21D79FDA237617C60057D00D /* SubscriptionEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D79FD9237617C60057D00D /* SubscriptionEvent.swift */; };
21D79FE32377F4120057D00D /* SubscriptionConnectionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D79FE22377F4120057D00D /* SubscriptionConnectionState.swift */; };
Expand Down Expand Up @@ -757,6 +758,7 @@
21A3FDB52464590600E76120 /* ModelMultipleOwnerAuthRuleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMultipleOwnerAuthRuleTests.swift; sourceTree = "<group>"; };
21A3FDB8246494CD00E76120 /* GraphQLRequestAuthRuleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLRequestAuthRuleTests.swift; sourceTree = "<group>"; };
21A3FDBE2465FA1500E76120 /* AuthRule+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AuthRule+Extension.swift"; sourceTree = "<group>"; };
21AD4255249BFFDF0016FE95 /* DeprecatedTodo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DeprecatedTodo.swift; path = Deprecated/DeprecatedTodo.swift; sourceTree = "<group>"; };
21C395B2245729EC00597EA2 /* AppSyncErrorType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSyncErrorType.swift; sourceTree = "<group>"; };
21D79FD9237617C60057D00D /* SubscriptionEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionEvent.swift; sourceTree = "<group>"; };
21D79FE22377F4120057D00D /* SubscriptionConnectionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionConnectionState.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2228,6 +2230,7 @@
B952182D237E21B900F53237 /* Models */ = {
isa = PBXGroup;
children = (
21AD4255249BFFDF0016FE95 /* DeprecatedTodo.swift */,
216E45E9248E91420035E3CE /* NonModel */,
FAF512AD23986791001ADF4E /* AmplifyModels.swift */,
214F49CB24898E8400DA616C /* Article.swift */,
Expand Down Expand Up @@ -4489,6 +4492,7 @@
21F40A4023A295470074678E /* TestCommonConstants.swift in Sources */,
214F497C2486D8A200DA616C /* UserFollowers.swift in Sources */,
B9521835237E21BA00F53237 /* Comment.swift in Sources */,
21AD4257249BFFE00016FE95 /* DeprecatedTodo.swift in Sources */,
216E45EF248E914F0035E3CE /* Todo+Schema.swift in Sources */,
FACA361E2327FC8E000E74F6 /* MockAnalyticsCategoryPlugin.swift in Sources */,
2129BE012394627B006363A1 /* PostCommentModelRegistration.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Amplify/Categories/DataStore/Model/Embedded.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
/// A `Embeddable` type can be used in a `Model` as an embedded type. All types embedded in a `Model` as an
/// `embedded(type:)` or `embeddedCollection(of:)` must comform to the `Embeddable` protocol except for Swift's Basic
/// types embedded as a collection. A collection of String can be embedded in the `Model` as
/// `embeddedCollection(of: String.self)` without needing to conform to Embeddable.
/// `embeddedCollection(of: String.self)` without needing to conform to Embeddable.
public protocol Embeddable: Codable {

/// A reference to the `ModelSchema` associated with this embedded type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public enum ModelFieldType {
}
}

@available(*, deprecated, message: """
This has been replaced with `.embedded(type)` and `.embeddedCollection(of)` \
Please use Amplify CLI 4.21.4 or newer to re-generate your Models to conform to Embeddable type.
""")
public static func customType(_ type: Codable.Type) -> ModelFieldType {
return .embedded(type: type)
}

public static func from(type: Any.Type) -> ModelFieldType {
if type is String.Type {
return .string
Expand Down
69 changes: 69 additions & 0 deletions AmplifyTestCommon/Models/Deprecated/DeprecatedTodo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// Copyright 2018-2020 Amazon.com,
// Inc. or its affiliates. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

// swiftlint:disable all
import Amplify
import Foundation
/*
The schema used to codegen this model:
type DeprecatedTodo @model {
id: ID!
description: String
note: Note
}
type Note {
name: String!
color: String!
}

Amplify CLI version used is less than 4.21.4. `.customType` has since been replaced with `.embedded(type)` and
`.embeddedCollection(of)`. Please use Amplify CLI 4.21.4 or newer to re-generate your Models to conform to
Embeddable type.
*/

public struct DeprecatedTodo: Model {
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
}
}

extension DeprecatedTodo {
// MARK: - CodingKeys
public enum CodingKeys: String, ModelKey {
case id
case description
case note
}

public static let keys = CodingKeys.self
// MARK: - ModelSchema

public static let schema = defineSchema { model in
let deprecatedTodo = DeprecatedTodo.keys

model.pluralName = "DeprecatedTodos"

model.fields(
.id(),
.field(deprecatedTodo.description, is: .optional, ofType: .string),
.field(deprecatedTodo.note, is: .optional, ofType: .customType(Note.self))
)
}
}

public struct Note: Codable {
var name: String
var color: String
}