Skip to content

Make the new Facet response Optional. #4907

@MichelDiz

Description

@MichelDiz

Experience Report

What you wanted to do

Query for facets and return it in an ideal format (which was the original behavior).

What you actually did

Query for my node and it returns an unwanted format that breaks my application.

Why that wasn't great, with examples

The PR #4267 has done a good and welcome change in Facet's behavior to solve an issue with List Type and Facets (adding support to facets on lists). Which is great. But, this breaks how things used to be done in Dgraph. And several users had to change their application or are blocked without fully understanding Facet's behavior. Confusing the process completely.

We explain in our docs how a JSON object is treated in Dgraph
e.g:

{
  "name": "Carol",
  "name|initial": "C",
  "dgraph.type": "Person",
  "friend": {
    "name": "Daryl",
    "friend|close": "yes",
    "dgraph.type": "Person"
  }
}

This object above explains in a logical way to the user how a facet should be treated (And indirectly we demonstrate how the structure would be in the response of a query with facets). However, when making a query we receive the same object in a completely different format. In a format that should be optional and perhaps mandatory for List Type only.

{
  q(func: has(friend)){
    name @facets
    dgraph.type
    friend @facets {
      name
      dgraph.type
    }
  }
}
{
  "data": {
    "q": [
      {
        "name": "Carol",
        "dgraph.type": [
          "Person"
        ],
        "friend": {
          "name": "Daryl",
          "dgraph.type": [
            "Person"
          ]
        },
        "friend|close": "yes"
      }
    ]
  }
}

This format above should be optional and bellow the default

{
  "data": {
    "q": [
      {
        "name": "Carol",
        "dgraph.type": [
          "Person"
        ],
        "friend": {
          "name": "Daryl",
          "friend|close": "yes",
          "dgraph.type": [
            "Person"
          ]
        }
      }
    ]
  }
}

Despite the change, this behavior does not affect the Value Facet at all.
If you query for:

{
  q(func: has(friend)){
    name @facets
  }
}

you gonna see (which is the previous behavior)

{
  "data": {
    "q": [
      {
        "name|initial": "C",
        "name": "Carol"
      }
    ]
  }
 }

Users are getting a bad experience from it.

Maybe we should make this behavior optional. Making possible to use the normal response (as always did) and a “map” response(as it is today).

e.g:

query {
  r(func: uid(0x01)) {
    seen @facets @map {
      uid
    }
  }
}

Any external references to support your case

https://docs.dgraph.io/mutations/#facets

https://discuss.dgraph.io/t/the-query-result-of-dgraph-v1-2-1-about-facets-looks-strange-did-i-miss-anything/5992
#4798
https://discuss.dgraph.io/t/facets-on-relations/5906

https://dgraphlabs.slack.com/archives/CSH96QK62/p1581011255272800
https://dgraph.slack.com/archives/C13LH03RR/p1583814358358000?thread_ts=1583813815.357600&cid=C13LH03RR

Metadata

Metadata

Labels

area/facetsIssues related to face handling, querying, etc.kind/bugSomething is broken.status/acceptedWe accept to investigate/work on it.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions