Skip to content

Commit 79c6482

Browse files
authored
feat(api): (Integ) SocialNote from codegen (#469)
1 parent 4ab2740 commit 79c6482

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

AmplifyPlugins/API/AWSAPICategoryPluginIntegrationTests/GraphQL/GraphQLWithUserPoolIntegrationTests/AuthDirective/GraphQLAuthDirectiveIntegrationTests+Support.swift

+1-9
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,9 @@ extension GraphQLAuthDirectiveIntegrationTests {
157157
XCTFail("underlying error should be AuthError, but instead was \(underlyingError ?? "nil")")
158158
return
159159
}
160-
guard case let .service(_, _, underlyingAuthError) = authError else {
160+
guard case .signedOut = authError else {
161161
XCTFail("Error should be AuthError.service")
162162
return
163163
}
164-
guard let awsCognitoAuthError = underlyingAuthError as? AWSCognitoAuthError else {
165-
XCTFail("Error should be AWSCognitoAuthError")
166-
return
167-
}
168-
guard case .signedOut = awsCognitoAuthError else {
169-
XCTFail("Error should be .signedOut")
170-
return
171-
}
172164
}
173165
}

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

+38-26
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,43 @@
88
import Amplify
99

1010
public struct SocialNote: Model {
11-
public let id: String
12-
public var content: String
13-
public var owner: String?
14-
public init(id: String = UUID().uuidString,
15-
content: String,
16-
owner: String?) {
17-
self.id = id
18-
self.content = content
19-
self.owner = owner
20-
}
21-
public enum CodingKeys: String, ModelKey {
22-
case id
23-
case content
24-
case owner
25-
}
26-
public static let keys = CodingKeys.self
27-
28-
public static let schema = defineSchema { model in
29-
let socialNote = SocialNote.keys
30-
model.authRules = [
31-
rule(allow: .owner, operations: [.create, .update, .delete])
32-
]
33-
model.fields(
34-
.id(),
35-
.field(socialNote.content, is: .required, ofType: .string),
36-
.field(socialNote.owner, is: .optional, ofType: .string))
11+
public let id: String
12+
public var content: String
13+
public var owner: String?
14+
15+
public init(id: String = UUID().uuidString,
16+
content: String,
17+
owner: String? = nil) {
18+
self.id = id
19+
self.content = content
20+
self.owner = owner
21+
}
22+
}
23+
24+
extension SocialNote {
25+
// MARK: - CodingKeys
26+
public enum CodingKeys: String, ModelKey {
27+
case id
28+
case content
29+
case owner
30+
}
31+
32+
public static let keys = CodingKeys.self
33+
// MARK: - ModelSchema
34+
35+
public static let schema = defineSchema { model in
36+
let socialNote = SocialNote.keys
37+
38+
model.authRules = [
39+
rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", operations: [.create, .update, .delete])
40+
]
41+
42+
model.pluralName = "SocialNotes"
43+
44+
model.fields(
45+
.id(),
46+
.field(socialNote.content, is: .required, ofType: .string),
47+
.field(socialNote.owner, is: .optional, ofType: .string)
48+
)
3749
}
3850
}

0 commit comments

Comments
 (0)