如何解决当只选择一个选项时,有没有办法减少 graphQL 中的重复性
现在我有一个突变,它为查询传递所有可能的参数,但我宁愿只传递一个并将数据库中的所有其余字段保持不变,而不是传递它们。
这是我的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 举报,一经查实,本站将立刻删除。