bobbyt
11/15/2017, 10:02 PMCombined
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.In my case, I am trying to update a set of tags on a Post. I am able to pass both
tags
(new tags) and tagsIds
(ids of tags that already exist) to my mutation:
const updatePostQuery = ({
id,
createdById,
timestamp,
imageUrl,
description,
tags,
tagsIds,
}) => ({
mutation: gql`
mutation updatePost(
$id: ID!
$createdById: ID!
$timestamp: DateTime!
$imageUrl: String
$description: String
$tags: [PosttagsTag!]!
$tagsIds: [ID!]
) {
updatePost(
id: $id
createdById: $createdById
timestamp: $timestamp
imageUrl: $imageUrl
description: $description
tags: $tags
tagsIds: $tagsIds
) {
id
timestamp
description
tags {
id
tag
}
imageUrl
createdBy {
id
username
}
}
}
`,
variables: {
id,
createdById,
timestamp,
imageUrl,
description,
tags,
tagsIds,
},
});
However, I get the following error:
ERROR: [Error: GraphQL error: A unique constraint would be violated on Post. Details: Sorry, no more details available.]
While the new tag is added successfully the mutation seems to be trying to append the ids of the existing tags to the field instead of updating their values?