GraphQl API 中的 AccessDenied 错误,无法弄清楚

问题描述

GraphQl PLayground Error screenshot (same error I get in the client)

大家好,我在处理一个小项目时遇到了一个非常令人沮丧的问题。我无法从客户端的购物车中删除商品,因为我收到了 accessDenied 错误。这个网站没有认证,也不应该。我希望网站上的每个人都能够随意添加删除购物车项目。我正在使用 GraphQl、Keystone 和 mongoDB,我已经在 keystone.js 数据库中尝试了所有方法来允许访问,我在所有列表上都有访问字段并将所有内容设置为 true。我可以在 graphQl Playground 中删除 CartItems,但不能在客户端或管理操场中删除。如果有人可以提供一些帮助或建议,将不胜感激,谢谢!

这是我的关键数据库

const { Keystone } = require('@keystonejs/keystone');
const { GraphQLApp } = require('@keystonejs/app-graphql');
const { AdminUIApp } = require('@keystonejs/app-admin-ui');
const { MongooseAdapter: Adapter } = require('@keystonejs/adapter-mongoose');
const FoodItem = require('./lists/FoodItem');
const Category = require('./lists/Category');
const Salad = require('./lists/Salad');
const Order = require('./lists/Order');
const saladCartItem = require('./lists/saladCartItem');
const foodCartItem = require('./lists/foodCartItem');
const Cart = require('./lists/Cart');
const PROJECT_NAME = 'ghost-grits';
const adapterConfig = { mongoUri: process.env.DATABASE_URL };

const keystone = new Keystone({
  adapter: new Adapter(adapterConfig),cookieSecret: process.env.COOKIE_SECRET,defaultAccess: {
    list: true,field: true
  }
});

keystone.createList('FoodItem',FoodItem)
keystone.createList('Category',Category)
keystone.createList('Salad',Salad)
keystone.createList('Order',Order)
keystone.createList('saladCartItem',saladCartItem)
keystone.createList('foodCartItem',foodCartItem)
keystone.createList('Cart',Cart)

module.exports = {
  keystone,apps: [new GraphQLApp({ isAccessAllowed: true }),new AdminUIApp({ name: PROJECT_NAME,enableDefaultRoute: true,isAccessAllowed: true })],};

这是访问字段,我在所有列表中都放了一个相同的字段:

const FoodItem = list({
  access: {
    read: true,update: true,delete: true,create: true
  },

解决方法

这是 Keystone 中的已知问题。如果您没有具有该商品 ID 的商品,即使没有设置访问控制,它也会给您 access denied 错误。

检查您的客户端应用程序是否正在向 graphql 发送正确的变量。您可以使用 chrome devtools 并查找 api 调用。确保查询正确并且变量具有正确的数据。您还可以通过使用该 ID 查询项目来检查是否返回任何结果。

enter image description here