reactjs - 在 GraphQL 突变响应中返回动态键
问题描述
我在这里发布的问题中看到了这个答案:来自 GraphQL 突变的动态响应
但我想知道自从这个答案以来,我是否可以根据我发送到服务器的参数以某种方式返回一个动态密钥。例如,如果我在客户端(React + apollo-client)中有一个更新用户特定密钥的地方:并且我只使用 1 个突变来更新用户,而不是为每个用户属性编写每个突变。
mutation updateUser(
$userUuid: String!
$userName: String
$userOtherDeepNestedObject: OtherDeepNestedObjectInput
...
) {
updateUser(
userUuid: $userUuid,
userUpdate: {
name: $userName,
otherDeepNestedObject: $userOtherDeepNestedObject
...
}
) {
uuid
name
otherDeepNestedObject {...} # this refetch will take long. i want to skip it, and only refetch if updated
...
}
}
所以我想做类似的事情:
mutation updateUser(
$userUuid: String!
$userName: String
$userOtherDeepNestedObject: OtherDeepNestedObject
) {
updateUser(
userUuid: $userUuid,
userUpdate: {
name: $userName,
otherDeepNestedObject: $otherDeepNestedObject
}
) {
uuid
[dynamicKey]
}
}
这样我只需要 uuid + 动态键就可以用返回的动态值更新本地 apollo 缓存。主要是为了减少服务器不必要地运行深度嵌套查询的时间,而不是为更新相同的实体类型而进行多个突变。
解决方案
推荐阅读
- css - Fluent UI Northstar 中的复选框大小
- php - 它是一个 JSON 字符串吗?在 PHP 中获取数组
- mysql - SQL 时差和按 3 列分组
- machine-learning - 如何对pdf原始数据进行K-Means聚类
- javascript - 如何在悬停的 div 周围添加边框,最好在单击扩展弹出窗口上的按钮后激活该功能?
- for-loop - 基于同一列的前一行填充列值的 DAX
- django - 覆盖与扩展 Django 的 models.Manager 以处理已删除的对象(最佳实践)
- javascript - 获取没有时区减法的日期 ISO 字符串
- typescript - 返回快速响应的 spyOn 函数,引发错误“响应”类型的参数
' 不可分配给“响应”类型的参数 - laravel - Laravel Migrate 中的未定义索引