Fun*_*nja 7 aws-appsync aws-amplify
我的项目使用 cognito 用户池作为默认身份验证方法,并且还将 iam 用于我的自定义 graphql lambda 解析器。
我一直在使用 AppSync 控制台对我的查询/突变运行测试。
我在这个 schema.graphql 文件中实现了 User 和 Group 类型之间的多对多关系。
type User
@model
@auth(
rules: [
{ allow: owner, ownerField: "id", operations: [create, update, delete] }
{ allow: private, provider: iam, operations: [read, update, delete] }
{ allow: private, provider: userPools, operations: [read] }
]
) {
id: ID!
displayName: String!
groups: [GroupMemberLink] @connection(keyName: "byMember", fields: ["id"])
}
type Group
@model
@auth(
rules: [
{ allow: owner, ownerField: "members", operations: [create, update, delete] }
{ allow: private, provider: iam, operations: [read, update, delete] }
{ allow: private, provider: userPools, operations: [read] }
]
) {
id: ID!
name: String!
members: [String]!
associated: [GroupMemberLink] @connection(keyName: "byGroup", fields: ["id"])
}
type GroupMemberLink
@model(queries: null, subscriptions: null)
@key(name: "byGroup", fields: ["groupID", "memberID"])
@key(name: "byMember", fields: ["memberID", "groupID"])
@auth(
rules: [
{ allow: private, provider: userPools, operations: [read] }
# what am I doing wrong below?
{ allow: private, provider: iam, operations: [create, read, update, delete] }
]
) {
id: ID!
groupID: ID!
memberID: ID!
group: Group! @connection(fields: ["groupID"])
member: User! @connection(fields: ["memberID"])
}
Run Code Online (Sandbox Code Playgroud)
我的意图:
我的问题:
当我从 User 或 Group 类型查询时,我的 lambda 函数无法读取此关系类型/字段。似乎用户能够创建这种类型的对象,这是我绝对不想要的。
我究竟做错了什么?我知道最近添加了多重身份验证,所以这可能很棘手。
阅读文档对我没有多大帮助,所以我一直在尝试许多不同的规则组合,并希望其中一种能奏效。
更新:每当我尝试访问用户或组类型的连接字段时,我都会收到此错误:Not Authorized to access items on type ModelGroupMemberLinkConnection"从 appsync 控制台使用 iam 作为身份验证类型。
澄清一下:使用 Cognito 用户池进行身份验证的用户具有读/写访问权限(不应具有写访问权限),但我使用 iam 的 lambda 函数没有读或写访问权限。
我尝试过的事情仍然导致在使用 iam 进行身份验证时无法访问相关字段:
@auth(rules: [{ allow: private, provider: iam, operations: [read, update, delete] }])更新:
这些是我一直在 AppSync 控制台中测试的查询:
query GetUser {
getUser(id: "funksouldev") {
id
displayName
groups {
items {
group {
id
name
}
}
}
}
}
query GetGroup($groupID: ID!) {
getGroup(id: $groupID) {
id
associated {
items {
id
member {
id
displayName
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
好的,最后我认为这可以解决问题。
type ModelGroupMemberLinkConnection @aws_iam
@aws_cognito_user_pools
{
items: [GroupMemberLink]
nextToken: String
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1494 次 |
| 最近记录: |