Adding multiple nodes and relations some of which may not exist

Hello everyone. I'm struggeling with inserting a small graph.
Here is the scenarion.

We have these entities:
moodle (e-learning application)

course is part of moodle
user has an account in moodle
user is enrolled in course
user is part of group
group is part of course
some more relations

now every time a user engages in an action we get a statement where all this data is provided and i want to add this data to the graph.

Now some of these nodes and relations might already exist.
And also entities like a course are not uniquely identified by their id but
by their id plus their connection to a moodle.

Is there a way to easly do this in one statement? I can't come up with a solution using merge.

So far it seems i have to split this up into multiple statements:
Merge (moodle)

Match (moodle) Merge (moodle)-[]-(course)

Match (moodle)-[]-(course) Merge (moodle)-[]-(group)

and so on and so on for the other nodes and relations.

Is there an easier way?
Thank you for your time.

So far where i have gotten is that you can atleast chain merges one after another lke this

Match (moodle:Moodle{name:"moodle"}) 
Merge (moodle)-[part:PART_OF]-(course:Course{id:"6"}) 
Merge (moodle)-[:PART_OF]-(course) 
Merge (course)-[:PART_OF]-(group:Group{name: "group s"})

Hello yassin-taskin and welcome to the community!

You should be able to create the nodes/relationships with MERGE as follows:

Match (moodle:Moodle{name:"moodle"})
Merge (moodle)-[:PART_OF]->(course:Course{id:"6"})
Merge (course)-[:PART_OF]->(:Group{name: "group s"})