我正在 AWS Lambda 上使用无服务器框架运行 GraphQL 服务器。
我正在使用 UI 中获取数据apollo-link-batch-http
.
如果我使用本地运行它serverless-offline
,效果很好。但如果我在 AWS Lambda 上运行它,它会成功解决fooResolver
但不是barResolver
因为它抛出上述错误消息。
The Model.cached(300)
是我制作的一个小型缓存包装器。你可以在这里看到它:https://gist.github.com/lookapanda/4676083186849bb6c5ae6f6230ad7d8f https://gist.github.com/lookapanda/4676083186849bb6c5ae6f6230ad7d8f它基本上只是让我能够使用我自己的findById
功能等。
奇怪的是,只有当我使用时才会出现此错误apollo-link-batch-http
但如果我使用则不会apollo-link-http
。因此,如果请求被批处理为单个 GraphQL 请求,则不会出现此类错误(尽管,然后我收到此错误:https://github.com/sequelize/sequelize/issues/9242 https://github.com/sequelize/sequelize/issues/9242)
我真的不知道那里发生了什么,在任何这些解析器中都没有原始的 where 查询。更奇怪的是:它只发生在缓存的结果中。第一个请求完全有效且成功,但随后每个连续请求都失败并显示上述错误消息。
我真的希望有人能帮助我,我快疯了:D
export const fooResolver = async () => {
const Model = db.getDB().sequelize.models.fooModel;
const data = await Model.cached(300).findAll({
where: {
time: {
[Op.gt]: Model.sequelize.literal('CURRENT_TIMESTAMP()'),
},
enabled: true,
state: 'PLANNED',
},
order: [['time', 'DESC']],
limit: 5,
});
return data.value;
};
export const barResolver = async () => {
const models = db.getDB().sequelize.models;
const Model = models.fooModel;
const data = await Model.findById(data.id, {
include: [
{
model: models.barModel,
include: [
{
association: 'fooAssociation',
include: [{ association: 'barAssociation' }],
order: ['showOrder', 'ASC'],
},
],
},
],
});
return {
data,
};
};