-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Known Issue] Mutations not correctly created for many-to-many relationship #479
Comments
This is currently by design. We need to add support for such capability to modify nested entities. |
Comes under nested mutations. |
Consider the tables: Here are some of the things that needs consideration
Please kindly let me know your thoughts |
In this proposal, what will be the mutation schema? Do the books mentioned already exist? If not, is there a way I can provide already existing book to associate the new author with existing book? |
I had wondered this for a while, how could you create entity relationships. If I have a book and an author, how do I create the relationship between them? |
The relationships can be created using CLI by using the following commands
Relationship fields:
|
Moving this to March2023 as this is not in scope for SWA-DAB Public Preview |
Is this still a limitation? Is there some sort of comprehensive log of DB operation limitations? Here's the schema changes needed to support this for the example data: ...
input CreateAuthorInput {
...
book_ids: [Int!]
}
input UpdateAuthorInput {
...
book_ids: [Int!]
}
input CreateBookInput {
...
author_ids: [Int!]
}
input UpdateBookInput {
...
author_ids: [Int!]
}
... Need to generate these with the corresponding resolver logic. |
I've been thinking about what could be a good approach here and my thought is that we should automatically generate the mutations required for editing relationships based off the relationship information present in the Let's take these entities and their relationship from the sample SQL database: "Author": {
"source": "dbo.authors",
"permissions": [
{
"role": "anonymous",
"actions": ["*"]
}
],
"relationships": {
"books": {
"cardinality": "many",
"target.entity": "Book",
"linking.object": "dbo.books_authors"
}
}
},
"Book": {
"source": "dbo.books",
"permissions": [
{
"role": "anonymous",
"actions": ["*"]
}
],
"relationships": {
"authors": {
"cardinality": "many",
"target.entity": "Author",
"linking.object": "dbo.books_authors"
}
}
} Presently, we have to map the "BookAuthor": {
"source": "dbo.books_authors",
"permissions": [
{
"role": "anonymous",
"actions": ["*"]
}
]
} For you, which in turn would generate If we wanted to take it a step further, we could generate a more specific "relationship" entity in the internal object structure and only generate the mutation Mutations {
createBookAuthors(bookId: Int! authorIds: [Int!]!): Book!
deleteBookAuthors(bookId: Int! authorIds: [Int!]!): Book!
createAuthorBooks(authorId: Int! bookIds: [Int!]!): Author!
deleteAuthorBooks(authorId: Int! bookIds: [Int!]!): Author!
} These would be specific mutations representing the relationship direction (starting with This can become more complex when the mapping table expands beyond two columns, but I'm not sure how common that is. |
@ayush3797 @severussundar can this item be tracked with nested mutations, if required? |
Hey @seantleonard, through the nested inserts feature, they would be able to accomplish what is described in the description ---> Create a book + associate it with a list of authors; both in a single operation. I've linked this issue to the parent issue for nested mutations. This is added as a related item in the parent issue. |
Through multiple create feature, this use-case is enabled now. When creating Books, Authors of those books can also be created. mutation {
createbook(
item: {
title: "Book #1"
publisher_id: 1234
authors: [
{ name: "Author #1", birthdate: "2001-01-01" }
{ name: "Author #2", birthdate: "2000-01-02" }
]
}
) {
id
title
authors {
items {
id
name
birthdate
}
}
}
} Note: Existing authors cannot be linked when creating a book through multiple create operation. In other words, there's no option to specify existing ids in the input object type for M:N relationships. |
Not sure if this is a bug or by design, but it seems that mutations do not reflect that many-to-many relationships. For example in a Book-Authors, when I use
createBook
to create a book I cannot specify the list of authors Id that should be associated with the book.The text was updated successfully, but these errors were encountered: