Update mutation (graphql) to add a many-to-many relationship without overwriting the whole thing

System Information
  • Strapi Version: 4.1.6
  • Operating System: macbook pro m1
  • Database: sqlite
  • Node Version: 14.18.3
  • NPM Version: 6.14.15
  • Yarn Version: 1.22.10

Problem/goal
I have a many-to-many relationship, and would like to add an entry on an update mutation without overwriting all previous records

Example mutation

mutation addField($foo:ID!, $bar:ID!) {
   updateEntry(id: $foo, data: { property: [$bar] }) {
      data {
         ...entrydata
      }
   }
}

Result I get

data {
   ...singleEntry
}

Desired result if running multiple times with different values for $bar

data {
   ...entry1
   ...entry2
   ...entry3
   ...entry4
}

Is anyone able to help me with this? Please let me know if I should add more detail to solve this problem.

Thanks

2 Likes

Hi @kd_coded , did you find a solution ?

I am stuck with the same problem, whether it’s with GraphQL or API REST, my relationship updates overwrite all previous relationships…

2 Likes

Same problem

Which Strapi version are you using?

4.1.8
I tried adding a relation to the user but it didn’t work. But it worked if you add
relation to the opposite collection

now I have a problem to remove the relation))

1 Like