@@ -1812,6 +1812,52 @@ describe('AppSyncSwiftVisitor', () => {
1812
1812
}"
1813
1813
` ) ;
1814
1814
} ) ;
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
+ } ) ;
1815
1861
} ) ;
1816
1862
it ( 'should support multiple auth rules' , ( ) => {
1817
1863
const schema = /* GraphQL */ `
@@ -1821,7 +1867,7 @@ describe('AppSyncSwiftVisitor', () => {
1821
1867
rules: [
1822
1868
{ allow: groups, groups: ["admin"] }
1823
1869
{ allow: owner, operations: ["create", "update"] }
1824
- { allow: public, operation : ["read"] }
1870
+ { allow: public, operations : ["read"] }
1825
1871
]
1826
1872
) {
1827
1873
id: ID!
@@ -1855,7 +1901,8 @@ describe('AppSyncSwiftVisitor', () => {
1855
1901
1856
1902
model.authRules = [
1857
1903
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])
1859
1906
]
1860
1907
1861
1908
model.pluralName = \\"Posts\\"
0 commit comments