Bug: Adding Facets via JSON

I’m attempting to create facets via JSON using the method outlined here: https://dgraph.io/docs/master/mutations/json-mutation-format/#facets-in-list-type-with-json

but it’s only working when using RDF _:Person <friends> _:Friend (order=0). Using the JSON version doesn’t create the facet:

{
  "set": [
    {
      "uid": "_:Person",
      "name": "Julian",
      "friends": [{"uid": "_:Friend", "name": "Bob"}],
      "friends|order": {
        "0": 0
      }
    }
  ]
}

Hi @jamilabreu
The example you have cited is for list-type predicates (list of strings, ints etc.). You are trying to create uid predicates (or nodes). Please try the following mutation.

{
  "set": [
    {
      "uid": "_:Person",
      "name": "James",      
      "friends": {
        "uid": "_:Friend",
        "name": "Bob",
        "friends|order": 0
      }
    }
  ]
}

This can be queried as below.

{
  q(func: eq(name,"James")){
    name
    friends @facets(order){
      name
    }
  }
}

Result:

{
  "data": {
    "q": [
      {
        "name": "James",
        "friends": [
          {
            "name": "Bob",
            "friends|order": 0
          }
        ]
      }
    ]
  }
}

You will find related documentation here.

1 Like

Got it! Thanks