检查数据源:首先确定您的数据源已经被正确配置。如果数据源连接有问题或数据源对象没有被正确地更新,GraphQL就不能正确地更新。
检查schema:检查schema文件以确保正确的类型被使用。当类型的名称不匹配、输入和输出类型不匹配或者类型不符合预期时,GraphQL可能会无法更新。
检查查询:查询参数的错误可能导致GraphQL无法更新。确保每个查询参数都包含正确的值,并且输入格式与定义的类型匹配。
代码示例:
在GraphQL请求中添加@cacheControl(maxAge: 60)
指令可以让缓存策略正常工作。
例如:
query GetUserData($id: Int!) {
user(id: $id) {
id
name
email
posts {
id
title
content
}
}
} @cacheControl(maxAge: 60)
在AWS lambda函数中,可以使用以下代码更新数据:
exports.handler = async (event, context) => {
const input = event.arguments;
const id = input.id;
const name = input.name;
// 更新数据
const result = await updateUser(id, name);
// TTL based cache update
await graphqlCloudWatchLogs.flushCacheEntry(event);
return result;
};