0
type User {
  user_name: String
  Age: Float
  Drinking: Boolean
  Nationality: String
  sex: String
  Smoking: Boolean
  Weight: Float
  sufferingFromDisease: disease @relationship(type: "suffering_from", direction: OUT)
  haveInFamilyHistory: history @relationship(type: "have_in_family", direction: OUT)
  activityOnTodayDate: today_date @relationship(type: "activity_on", direction: OUT)
}

type disease {
  disease_name: String
  Medication: String
  Time_period: Float
  userSufferingFrom: User @relationship(type: "suffering_from", direction: IN)
}

I am using this type definitions in graphql to create the graph. I have created the user node and disease node without relations. Now i want to create the relations without editing the nodes like merge in the cypher. can some one help

mutation{
  createUsers(input:{
    sufferingFromDisease
  })
  {
    users{
      sufferingFromDisease
    }
  }
}

I was trying this above mutation to create relations but no luck

1 Answers1

0

If you want to create a relationship when 2 nodes already exist in the database, you should perform an update operation with a connect parameter, such as:

mutation Mutation {
  updateUsers(
    where: { user_name: "arthur_dent" }
    connect: { sufferinFromDisease: { where: { node: { disease_name: "Great Green Arkleseizure" } } } }
  ) {
    users {
      user_name
     }
  }
}

Sadly, documentation on this area is a bit lacking, although any introspection tool such as GraphiQL will help you find all the alternatives and syntax for connections.

You can find a few examples following the relationships section of the official documentation

angrykoala
  • 3,774
  • 6
  • 30
  • 55