我正在尝试使用 update: 在执行突变后更新查询。问题是商店中的查询应用了多个不同的变量,我想更新查询并使用相同的变量返回它。
我在文档中发现 updateQueries 有一个包含 queryVariables 的选项,它们是执行查询时使用的最后一组变量。
我还没有找到任何描述如何从更新内部检索 queryVariables 或类似内容的内容。
更新内部:我可以使用
lastQuery = Object.keys(store.data.ROOT_QUERY).slice(-1)[0]
这将返回类似的结果"userRecipes({"first":20,"minTime":0,"maxTime":500,"filterType":"Explore","searchTerm":""})"
我现在这样做的黑客方法是解析该字符串以提取变量,这样我最终可以像这样使用 readQuery:
const lastQuery = Object.keys(store.data.ROOT_QUERY).slice(-1)[0]
const searchPosition = lastQuery.search("searchTerm")
const searchTerm = lastQuery.slice((searchPosition + 13),-3)
// also parsing the lastQuery string for filterType, minTime, maxTime
const data = store.readQuery({
query: QUERY_USER_RECIPES,
variables: {
filterType: filterType,
searchTerm: searchTerm,
minTime: minTime,
maxTime: maxTime,
}
});
这不是最好的方法。有没有更简单的方法来访问更新内部的变量?
似乎应该有一种方法可以读取存储中的现有查询和变量,而无需使用 readQuery 传递变量。
感谢您关注这个问题!
Version
[电子邮件受保护] /cdn-cgi/l/email-protection
[电子邮件受保护] /cdn-cgi/l/email-protection