Modifying predicate lists

Hi David Di Biase,

Sure you can do it, I’ll show you.

Let’s create our List:

{
  set{
    _:MyList <testList> "Banana" .
    _:MyList <testList> "Apple" .
    _:MyList <testList> "watermelon" .
    _:MyList <testList> "Strawberry" .
    _:MyList <testList> "Grape" .
  }
}

Now We search for that Node to get its UID:

{
  MyList(func: has(testList)) {
    uid
    expand(_all_)
  }
}

The result will be:

{
  "data": {
    "MyList": [
      {
        "uid": "0x2711",
        "testList": [
          "Grape",
          "Strawberry",
          "Banana",
          "Apple",
          "watermelon"
        ]
      }
    ]
  }

Now we wanna delete just one fruit (Apple) from our list (It’s case sensitive):

{
  delete  {
    <0x2711> <testList> "Apple" .
  }
}

The result will be:

{
  "data": {
    "MyList": [
      {
        "uid": "0x2711",
        "testList": [
          "Grape",
          "Strawberry",
          "Banana",
          "watermelon"
        ]
      }
    ]
  }

That’s all,
Any doubt I am available.

Cheers.

1 Like