bobbyt
11/16/2017, 1:52 PMupsert
when issuing a mutation on a nested one-to-many field. In my case, I have a Post
type than has a tag
field which can be associated with many `Tag`s. The issue I am running into is when updating a Post
- I need to both create new `Tag`s for tags that do not yet exist, and for ones that do only provide an association to existing Tag
ids. Here is my schema:
type Post @model {
createdAt: DateTime!
createdBy: User @relation(name: "PostsByUser")
description: String @defaultValue(value: "''")
id: ID! @isUnique
tags: [Tag!]! @relation(name: "TagsOfPost")
...
}
type Tag @model {
id: ID! @isUnique
tag: String!
createdBy: User @relation(name: "TagsByUser")
createdAt: DateTime!
posts: [Post!]! @relation(name: "TagsOfPost")
}
I came across this post by @nilan but it's not clear how to implement the combined method he outlines:
https://www.graph.cool/forum/t/how-do-i-add-an-array-of-objects-to-a-mutation-in-apollo-react/365/6
Combined
You can also use tags and tagsIds in the same mutation, this would connect the new Tutorial node to all the tags in tagsIds and connect it to the new tags in tags. This is what you want to do if you want to only allow tags with a unique text, so for a new Tutorial, there will likely be some tags that already exists, and some that need to be created.Is it currently impossible to do this with one mutation? Would a second mutation be required to add the associations to existing
Tag
ids? Thanks!