当从GraphQL服务器查询数据时,urql添加一个_typename字段来跟踪缓存:
{
__typename "Book"
name "test"
description "the book"
id "hPl39w4rzc2HZxkfHDyj"
auther "John Doe"
}我想更新这个对象并将其保存回数据库。当useMutation函数被调用时,__typename也被传递,并且由于它不是服务器模式的一部分,它将导致一个错误:
Field \"__typename\" is not defined by type我知道在调用useMutation之前我可以这样做:
delete input.__typename;但我想知道在全球范围内是否有更好的方法来处理urql?例如,在阿波罗客户机中,您可以在更新之前使用ApolloLink从所有变量中删除__typename。
发布于 2021-05-18 22:41:16
const result = {
__typename: "Book",
name: "test",
description: "the book",
id: "hPl39w4rzc2HZxkfHDyj",
auther: "John Doe"
}
const {__typename, ...rest} = result;
console.log(rest)最好在graphql客户机中的对象上保留这个标记,因为它可以帮助缓存完成它的任务。因此,您可以根据需要删除它--在这里您可以更新"rest“,并使用它来调用您的更新突变。
https://stackoverflow.com/questions/67594809
复制相似问题