Graphql - 无权访问来自 AWS AppSync Amplify 控制台的错误消息 [英] Graphql - Not Authorized to access error message from AWS AppSync Amplify Console
本文介绍了Graphql - 无权访问来自 AWS AppSync Amplify 控制台的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 React + NextJs 并实现了 Amplify Graphql.我已登录并将当前用户设置为管理员组,但是,我无法根据 authorId 更改数据.
I'm working with React + NextJs and have Amplify Graphql implemented. I'm logged in and set my current user as an Admin group, however, I'm not able to mutate a data based on authorId.
登录的用户ID是1234(例如)
The logged in userId is 1234 (for example)
type Xp
@model
@key(name: "xpsByUserId", fields: ["authorId"])
@auth(
rules: [
{ allow: owner, ownerField: "authorId" }
{ allow: public, operations: [read] }
{ allow: private, operations: [read] }
]
) {
id: ID!
authorId: ID!
author: User @connection(fields: ["authorId"])
name: String
visibility: Visibility
post: [Post] @connection(name: "XpPosts")
createdAt: String
}
尝试变异:
mutation MyMutation {
createXp(input: {authorId: "1234", name: "fdsfa"}) {
id
name
author {
username
}
}
}
我收到一条消息:无权访问 Xp 类型的 createXp
这是我的用户类型:
type User
@model(subscriptions: null)
@key(fields: ["userId"])
@auth(
rules: [
{ allow: groups, groups: ["Admin"] }
{ allow: owner, ownerField: "userId" }
{ allow: private, operations: [read] }
]
) {
userId: ID!
username: String!
email: String!
posts: [Post] @connection(keyName: "postsByUserId", fields: ["userId"])
xps: [Xp] @connection(keyName: "xpsByUserId", fields: ["userId"])
createdAt: String
updatedAt: String
following: [Following] @connection(keyName: "followingByUserId", fields: ["userId"])
}
我在这里做错了什么?
推荐答案
按照 link,
type Xp
@model
@key(name: "xpsByUserId", fields: ["authorId"])
@auth(
rules: [
{ allow: owner, ownerField: "authorId", operations: [create, delete, read, update] },
{ allow: groups, groups: ["Admin"], operations: [create, delete, read, update] },
{ allow: public, operations: [read] },
{ allow: private, operations: [read] }
]
) {
id: ID!
authorId: ID!
author: User @connection(fields: ["authorId"])
name: String
visibility: Visibility
post: [Post] @connection(name: "XpPosts")
createdAt: String
}
这篇关于Graphql - 无权访问来自 AWS AppSync Amplify 控制台的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文