Unique Constraint on string

You need to use the @id directive on the field you want to act as a unique key.

For example, with your data:

type Container {
  containerId: String! @id
  name: String # must be nullable, don't use String! here
  parent: Container
}

Now, inserting/upserting the following

    {
        "name": "test1",
        "parent": {
            "containerId": "parent1"
        },
        "containerId": "container1"
    },

will produce two nodes, one with all this data and one with just the containerId “parent1”.

Then, inserting/upserting

    {
        "name": "test2",
        "parent": {
            "containerId": "parent1"
        },
        "containerId": "container2"
    }

will create one new node, and link the parent field to the existing Container with containerId “parent1”.

However, the “parent1” Container still only has a containerId field, it does not have a name – you need to upsert that information separately if needed.

In any case, this approach allows you to create unique nodes per containerId, and it also automatically creates an empty-ish parent node, so you don’t need to inject any UIDs anywhere, and can manage your data completely from business key land. :grinning_face_with_smiling_eyes: