How to set relationships

Ok this might sound stupid but I am very new to graphql and dgraph. My schema is as followed

type FormQuestion  {
	id: Int 
  UUID: String! @search(by:[exact]) 
  projectID: ProjectEntry @hasInverse(field: "questions")
	title: String 
	type: String 
	required: Boolean 
	options: [String] 
	multi: Boolean 
}

type ProjectEntry  {
	UUID: String! @id 
	type: Int 
	name: String @search(by:[exact]) 
	description: String 
	createdAt: DateTime 
	updatedAt: DateTime 
	owner: String @search(by:[exact])
	color: String 
	collaborators: [String] @search(by:[exact])
	submitDescription: String 
	imageTitle: String 
	formDescription: String 
	questions: [FormQuestion!] 
	title: String 
        image: String
        authentication: String
        password: String
}

In my code I use, the below code to attempt to delete all FormQuestion, now I know this is wrong but how do i delete them, without going through each ID and deleting them.

mutation MyQuery {
  updateProjectEntry(input: {filter: {UUID: {eq: "23a8b593-27a6-4a6c-8bd5-2ec6da2a2c4c"}}, set: {questions: []}}) {
    numUids
  }
}

– Harvey

1 Like

Hello @Gerald12344
You have two options:
1- Delete questions using deleteFormQuestion, You need to get these questions ids.
1- Disconnect these questions from your form using a query like this:

mutation MyQuery {
  updateProjectEntry(input: {filter: {UUID: {eq: "23a8b593-27a6-4a6c-8bd5-2ec6da2a2c4c"}}, 
    remove: {
        questions: [{FormQuestionID: "0x1"}]
     }
}
) {
    numUids
  }
}

In both ways you need the ids

1 Like
upsert {
    query {
        var(func: type(typeName), first: 50000, offset: 0) {
            Type as uid
        }

    }
    mutation {
        delete {
            uid(Type) *  * .
        }
    }
}