@auth directive를 사용할 때, **allow**와 **operations**를 주의깊게 사용해야 한다는 내용이 문서에 있다
rules: [{allow: owner, operations: [read]}] ← bad case
rules: [{allow: owner, operations: [read update delete]}] ← good case
Cognito group으로 가입시키기
가입된 회원으로 쿼리 시 Authorization 걸기
type Salary @model @auth(rules: [{allow: groups, groups: ["Admin"]}]) {
id: ID!
wage: Int
currency: String
}
type Draft @model
@auth(rules: [
# Defaults to use the "owner" field.
{ allow: owner },
# Authorize the update mutation and both queries. Use `queries: null` to disable auth for queries.
{ allow: owner, ownerField: "editors", operations: [update] },
# Admin users can access any operation.
{ allow: groups, groups: ["Admin"] }
]) {
id: ID!
title: String!
content: String
owner: String
editors: [String]!
}
groupsField argument: String or [String]# Dynamic group authorization with multiple groups
type Post @model @auth(rules: [{allow: groups, groupsField: "groups"}]) {
id: ID!
title: String
groups: [String]
}
# Dynamic group authorization with a single group
type Post @model @auth(rules: [{allow: groups, groupsField: "group"}]) {
id: ID!
title: String
group: String
}
type Draft @model
@auth(rules: [
# **Static:** Defaults to use the "owner" field.
{ allow: owner },
# **Static:** Authorize the update mutation and both queries. Use `queries: null` to disable auth for queries.
{ allow: owner, ownerField: "editors", operations: [update] },
# **Static:** Admin users can access any operation.
{ allow: groups, groups: ["Admin"] }
# **Dynamic:** Each record may specify which groups may read them.
{ allow: groups, groupsField: "groupsCanAccess", operations: [read] }
]) {
id: ID!
title: String!
content: String
owner: String
editors: [String]!
groupsCanAccess: [String]!
}
resolver에서 $ctx.identity.username 으로 authorization validation을 진행