prisma1 icon indicating copy to clipboard operation
prisma1 copied to clipboard

Disconnect operations on unconnected nodes should be silently ignored

Open marktani opened this issue 5 years ago • 8 comments

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

marktani avatar Oct 15 '18 12:10 marktani

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
  }
}

mcmar avatar Oct 17 '18 03:10 mcmar

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.

stale[bot] avatar Jan 09 '19 03:01 stale[bot]

Any update on this? Seems like a pretty good idea =)

vjsingh avatar Mar 01 '19 15:03 vjsingh

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.

manonthemat avatar Mar 28 '19 02:03 manonthemat

is there any workaround before this gets implemented other than just catching the error?

tafelito avatar Jun 04 '19 02:06 tafelito

@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
                    };
                })
            }
        }
    });

serendipity1004 avatar Jul 02 '19 05:07 serendipity1004

Still waiting for...

Fi1osof avatar Jan 23 '20 08:01 Fi1osof

Still waiting for.. 2

silvacpp avatar Jul 01 '20 15:07 silvacpp