Skip to content

Commit

Permalink
feat(api): (Integ) SocialNote from codegen (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha authored May 20, 2020
1 parent 4ab2740 commit 79c6482
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,9 @@ extension GraphQLAuthDirectiveIntegrationTests {
XCTFail("underlying error should be AuthError, but instead was \(underlyingError ?? "nil")")
return
}
guard case let .service(_, _, underlyingAuthError) = authError else {
guard case .signedOut = authError else {
XCTFail("Error should be AuthError.service")
return
}
guard let awsCognitoAuthError = underlyingAuthError as? AWSCognitoAuthError else {
XCTFail("Error should be AWSCognitoAuthError")
return
}
guard case .signedOut = awsCognitoAuthError else {
XCTFail("Error should be .signedOut")
return
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,43 @@
import Amplify

public struct SocialNote: Model {
public let id: String
public var content: String
public var owner: String?
public init(id: String = UUID().uuidString,
content: String,
owner: String?) {
self.id = id
self.content = content
self.owner = owner
}
public enum CodingKeys: String, ModelKey {
case id
case content
case owner
}
public static let keys = CodingKeys.self

public static let schema = defineSchema { model in
let socialNote = SocialNote.keys
model.authRules = [
rule(allow: .owner, operations: [.create, .update, .delete])
]
model.fields(
.id(),
.field(socialNote.content, is: .required, ofType: .string),
.field(socialNote.owner, is: .optional, ofType: .string))
public let id: String
public var content: String
public var owner: String?

public init(id: String = UUID().uuidString,
content: String,
owner: String? = nil) {
self.id = id
self.content = content
self.owner = owner
}
}

extension SocialNote {
// MARK: - CodingKeys
public enum CodingKeys: String, ModelKey {
case id
case content
case owner
}

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

public static let schema = defineSchema { model in
let socialNote = SocialNote.keys

model.authRules = [
rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", operations: [.create, .update, .delete])
]

model.pluralName = "SocialNotes"

model.fields(
.id(),
.field(socialNote.content, is: .required, ofType: .string),
.field(socialNote.owner, is: .optional, ofType: .string)
)
}
}

0 comments on commit 79c6482

Please sign in to comment.