问题描述
现在我有一个突变,它为查询传递所有可能的参数,但我宁愿只传递一个并将数据库中的所有其余字段保持不变,而不是传递它们。
这是我的graphql
const UPDATE_CATALOG_STATUS = gql`
mutation UpdateCatalogStatus(
$id: ID!
$decor: Boolean
$clothing: Boolean
$supplies: Boolean
$furniture: Boolean
) {
updateCatalog(
id: $id
data: {
decor: $decor
clothing: $clothing
supplies: $supplies
furniture: $furniture
}
) {
clothing
decor
supplies
furniture
}
}
`;
在这里我检查每个项目是否存在
if (data.catalogType === "decor") {
decor = false;
} else {
decor = true;
}
if (data.catalogType === "clothing") {
clothing = false;
} else {
clothing = true;
}
if (data.catalogType === "supplies") {
supplies = false;
} else {
supplies = true;
}
if (data.catalogType === "furniture") {
furniture = false;
} else {
furniture = true;
}
const res = await updateCatalogStatusFunc({
variables: {
id: catalogData?.findUserByID?.catalog?._id,decor,clothing,supplies,furniture,},}).catch(console.error);
有没有办法只传递一个变量并让 graphQL 找出将它放在哪里而不是传递所有变量? Id 是必要的,但我可以根据用途选择有条件地传递其他人吗。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)