Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Many-to-many relationships have strange selection set structure #1342

Open
lastmjs opened this issue May 29, 2020 · 1 comment
Open

Many-to-many relationships have strange selection set structure #1342

lastmjs opened this issue May 29, 2020 · 1 comment

Comments

@lastmjs
Copy link

lastmjs commented May 29, 2020

If I have a many-to-many relationship, I have to use a join table. The join table becomes the type of the side of the relationship that I care about, which then has each member of the many-to-many relationship. I would much rather just have the type of the side of the relationship that I care about be the direct and only type. If I have a many-to-many relationship from Users to Posts, I want the posts field on Users to be an array of Posts, not an array of objects with a post and a user.

@lastmjs
Copy link
Author

lastmjs commented Jul 28, 2020

It would be great to have a simplification of many-to-many relationships, as discussed here: #936 (comment)

Also, the mutations for relationships in general I think could be improved. I think it's unnecessarily complicated to have to expose the _id field for relations when updating or creating entities. We shouldn't have to think in terms of id's like that when handling relations at the schema level.

Prisma had a really nice way of doing this, it looked something like the following. Imagine you have a user and a blog post, and you want to create a relation between them:

The user has already been created, and has id: 1
The blog post has already been created, and has id: 2

mutation {
  updateUsers(input: {
    blogPost: {
      connect: {
        id: 2
    }
  }
}

I'm not saying the way they did it was perfect or could not be improved, but it's more declarative. Also, this could work for many-to-many relationships as well. Right now, for many-to-many relationships you have to create a new entry in a join table to connect two entities. It would be much simpler to use syntax like the above.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant