Skip to content

Commit

Permalink
feat(amplify-codegen-appsync-model-plugin): iOS add suport for auth (a…
Browse files Browse the repository at this point in the history
…ws-amplify#4329)

Updated model gen to add authRules when @auth directive is used in schema
A schema with @auth directive 
type Post @model @auth(rules: [{ allow: owner }]) {
    id: ID!
    title: String!
    owner: String!
}

will generate the following authRule in Post+schema.swift

import Amplify
import Foundation
extension Post {
   
  public static let schema = defineSchema { model in
    let post = Post.keys
    
    model.authRules = [
      rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", operations: [.create, .update, .delete, .read])
    ]
    
    model.pluralName = "Posts"
    
    }
}
  • Loading branch information
yuth authored May 20, 2020
1 parent b9b697f commit 05cc6fc
Show file tree
Hide file tree
Showing 6 changed files with 534 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('process auth directive', () => {
const processedAuthDirective = processAuthDirective(directives);
expect(processedAuthDirective[0].arguments.rules[0]).toEqual({
...ownerAuthRule,
operations: [AuthModelOperation.create, AuthModelOperation.update, AuthModelOperation.delete],
operations: [AuthModelOperation.create, AuthModelOperation.update, AuthModelOperation.delete, AuthModelOperation.read],
});
});

Expand Down Expand Up @@ -164,7 +164,7 @@ describe('process auth directive', () => {
const processedAuthDirective = processAuthDirective(directives);
expect(processedAuthDirective[0].arguments.rules[0]).toEqual({
...groupsAuthRule,
operations: [AuthModelOperation.create, AuthModelOperation.update, AuthModelOperation.delete],
operations: [AuthModelOperation.create, AuthModelOperation.update, AuthModelOperation.delete, AuthModelOperation.read],
});
});
});
Expand Down
Loading

0 comments on commit 05cc6fc

Please sign in to comment.