@@ -1812,6 +1812,52 @@ describe('AppSyncSwiftVisitor', () => {
18121812 }"
18131813 ` ) ;
18141814 } ) ;
1815+
1816+ it ( 'should generate class with private authorization' , ( ) => {
1817+ const schema = /* GraphQL */ `
1818+ type Post @model @auth(rules: [{ allow: private }]) {
1819+ id: ID!
1820+ title: String!
1821+ }
1822+ ` ;
1823+ const visitor = getVisitor ( schema , 'Post' , CodeGenGenerateEnum . metadata ) ;
1824+ const generatedCode = visitor . generate ( ) ;
1825+ expect ( generatedCode ) . toMatchInlineSnapshot ( `
1826+ "// swiftlint:disable all
1827+ import Amplify
1828+ import Foundation
1829+
1830+ extension Post {
1831+ // MARK: - CodingKeys
1832+ public enum CodingKeys: String, ModelKey {
1833+ case id
1834+ case title
1835+ case createdAt
1836+ case updatedAt
1837+ }
1838+
1839+ public static let keys = CodingKeys.self
1840+ // MARK: - ModelSchema
1841+
1842+ public static let schema = defineSchema { model in
1843+ let post = Post.keys
1844+
1845+ model.authRules = [
1846+ rule(allow: .private, operations: [.create, .update, .delete, .read])
1847+ ]
1848+
1849+ model.pluralName = \\"Posts\\"
1850+
1851+ model.fields(
1852+ .id(),
1853+ .field(post.title, is: .required, ofType: .string),
1854+ .field(post.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime),
1855+ .field(post.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime)
1856+ )
1857+ }
1858+ }"
1859+ ` ) ;
1860+ } ) ;
18151861 } ) ;
18161862 it ( 'should support multiple auth rules' , ( ) => {
18171863 const schema = /* GraphQL */ `
@@ -1821,7 +1867,7 @@ describe('AppSyncSwiftVisitor', () => {
18211867 rules: [
18221868 { allow: groups, groups: ["admin"] }
18231869 { allow: owner, operations: ["create", "update"] }
1824- { allow: public, operation : ["read"] }
1870+ { allow: public, operations : ["read"] }
18251871 ]
18261872 ) {
18271873 id: ID!
@@ -1855,7 +1901,8 @@ describe('AppSyncSwiftVisitor', () => {
18551901
18561902 model.authRules = [
18571903 rule(allow: .groups, groupClaim: \\"cognito:groups\\", groups: [\\"admin\\"], operations: [.create, .update, .delete, .read]),
1858- rule(allow: .owner, ownerField: \\"owner\\", identityClaim: \\"cognito:username\\", operations: [.create, .update])
1904+ rule(allow: .owner, ownerField: \\"owner\\", identityClaim: \\"cognito:username\\", operations: [.create, .update]),
1905+ rule(allow: .public, operations: [.read])
18591906 ]
18601907
18611908 model.pluralName = \\"Posts\\"
0 commit comments