获取未经授权的错误-AWS GraphQl查询
我正在尝试从AWS GraphQl API获取一些数据:
这是模型:
type List @model @auth(rules: [{ allow: public, operations: [read] }]) {
id: ID!
title: String!
sprints: [Sprint] @hasMany(indexName: "byList", fields: ["id"])
organizationID: ID! @index(name: "byOrganization")
}
这就是我获取它的方式:
async function fetchLists() {
try {
const listData = await API.graphql({
query: listLists,
authMode: "AMAZON_COGNITO_USER_POOLS",
});
const lists = listData.data.listLists.items;
setLists(lists);
console.log({ lists });
} catch (err) {
console.log({ err });
}
}
useEffect(() => {
(async () => {
await fetchLists();
})();
}, []);
我什至在这里不需要任何auth规则,但它也不起作用。
有一个授权标题,但仍会遇到错误。
I'm trying to get some data from the AWS GraphQL API:
Here is the model:
type List @model @auth(rules: [{ allow: public, operations: [read] }]) {
id: ID!
title: String!
sprints: [Sprint] @hasMany(indexName: "byList", fields: ["id"])
organizationID: ID! @index(name: "byOrganization")
}
And this is how I fetch it:
async function fetchLists() {
try {
const listData = await API.graphql({
query: listLists,
authMode: "AMAZON_COGNITO_USER_POOLS",
});
const lists = listData.data.listLists.items;
setLists(lists);
console.log({ lists });
} catch (err) {
console.log({ err });
}
}
useEffect(() => {
(async () => {
await fetchLists();
})();
}, []);
I don't even need any auth rules here, but it doesn't work either.
There is an authorization header, but still getting the error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将模式更改为此,以允许
apikey
如果您有多种授权类型。并删除authmode:“ Amazon_Cognito_user_pools”
从您的代码中。Try changing your schema to this to allow
apiKey
authorization If you have multiple authorization types. And removeauthMode: "AMAZON_COGNITO_USER_POOLS"
from your code.