prisma1
prisma1 copied to clipboard
Disconnect operations on unconnected nodes should be silently ignored
Is your feature request related to a problem? Please describe.
Currently running a nested disconnect
operation results in this error message:
The relation ClientToUser has no node for the model Client with the value 'cjnaabi1ue0e30b68072s6avk' for the field 'id' connected to a node for the model User on your mutation path.
For this datamodel:
type User {
id: ID! @unique
name: String!
}
type Client {
id: ID! @unique
user: User
name: String!
}
and this mutation, if executed at max twice:
mutation b {
updateClient(
where: {
id: "cjnaabi1ue0e30b68072s6avk"
}
data: {
user: {
disconnect: true
}
}
) {
id
}
}
Describe the solution you'd like Instead of throwing an error, there should be an option to silently ignore this situation.
Describe alternatives you've considered We could think of a way to allow to choose whether or not to throw an error in this situation on the scope of a server, service, or type.
Additional context Original forum discussion: https://www.prisma.io/forum/t/disconnect-regardless-having-a-connection-or-not/4558?u=nilan
I agree that by default, disconnects should be idempotent. It's not technically a failure if it was already disconnected. Similar situation to the one above:
# datamodel
type User {
id: ID! @unique
name: String!
}
type Client {
id: ID! @unique
users: [User!]!
name: String!
}
# mutation
mutation b {
updateClient(
where: {
id: "cjnaabi1ue0e30b68072s6avk"
}
data: {
users: {
disconnect: {
id: "cjb68072s6avknaabi1ue0e30"
}
}
}
) {
id
}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.
Any update on this? Seems like a pretty good idea =)
I fully support this. Since I just started using this project I was wondering if one could point me in the right direction to get started on the issue if there hasn't been already work done.
is there any workaround before this gets implemented other than just catching the error?
@tafelito you could manually check if the element you want to delete exists. Something like below
const voteCategories = await prisma.post({id: postId}).voteCategories();
const disconnectTargets = await prisma.user({id}).votedPostCategories({
where: {
id_in: voteCategories.map(item => item.id)
}
});
const user = await prisma.updateUser({
where: {
id
},
data: {
votedPostCategories: {
disconnect: disconnectTargets.map(item => {
return {
id: item.id
}
}),
connect: voteCategoryIds.split(',').map((item : string) => {
return {
id: item
};
})
}
}
});
Still waiting for...
Still waiting for.. 2