How to Connect multiple documents in many to many relationships?

I’ve schema as such:

type Test {
	topic: String!
	asks: [Question!] @relation
}

type Question {
	topic: String!
	question: String!
	asked: [Test!] @relation 
}

I’ve already populated the Question collection. Now I’ll be creating new test that will have random questions connected to them. I searched in faunadb documentation and tutorials. All I could find was something similar to:

mutation create {
  createTest(
    data: {
      topic:"test",
      asks: {connect:324124898071937617}
    }
  ) {
    _id
  }
}

**

My question : Is there any way that I could connect more than one data like 10 at a time.

**

Following code returns error

mutation create {
  createTest(
    data: {
      topic:"test",
      asks: [{connect:324124898071937617}]
    }
  ) {
    _id
  }
}

Hi @dit.sagar,

First, welcome to the Fauna forums! I hope you’re able to get all the assistance you need here.

You’re on the right path with connecting more than one item at a time, you just have to think about it a little differently. From the GraphQL point of view, you’re telling it to create one or more connections on the asks attribute. But that would still only be a single command, so passing a list of commands like you’re doing wouldn’t be semantically correct. Instead, you’d pass the single command ("connect") with a list of targets:

mutation create {
  createTest(
    data: {
      topic:"Bridge Keeper testing",
      asks: {connect: [
        325671404371443783,
        325671617843691591,
        325672216533401671
      ]}
    }
  ) {
    _id
    asks {
      data {
        question
      }
    }
  }
}

This results in:

{
  "data": {
    "createTest": {
      "_id": "325672301447086151",
      "asks": {
        "data": [
          {
            "question": "What is your name?"
          },
          {
            "question": "What is your quest?"
          },
          {
            "question": "What is the capital of Assyria?"
          }
        ]
      }
    }
  }
}