我正在尝试从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();
})();
}, []);
我甚至不需要任何验证规则,但它也不能工作。
有一个授权报头,但仍然得到错误。
如果您有多种授权类型,请尝试将模式更改为允许apiKey
授权。并从代码中删除authMode: "AMAZON_COGNITO_USER_POOLS"
。
type List
@model
@auth(
rules: [
{ allow: public, operations: [read], provider: apiKey }
]
) {
...
}