Is there a way to create multiple relation at once in hygraph?

60 Views Asked by At

I am currently using hygraph as CMS. I have two models, posts and tags. I created many to many relation between them. It works when I use the inbuilt content editor.

The problem is that I cannot do the same with API. I can only create one relation at a time.

So is there a way to create multiple relation at once via API?

1

There are 1 best solutions below

0
Knight2056 On

I figured this out by hit and trial.

mutation MyMutation {
  createContent(
    data: {title: "ABC", genres: {connect: [{Genre: {type: "travel"}},{Genre: {type: "food"}}]}}
  ) {
    id
  }
}

You have to pass array of individual genres to connect.