Query for facets and return it in an ideal format (which was the original behavior).
Query for my node and it returns an unwanted format that breaks my application.
The PR https://github.com/dgraph-io/dgraph/pull/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
}
}
}
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
https://github.com/dgraph-io/dgraph/issues/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
Thank you for helping me raising the issue upon.
I don't really see the issue and reason why we change the facets response to the way it is now. But at a dgraph's user perspective, I think it would make more sense to have same data struct for creating or querying facets value.
And putting facets value inside the object would give a better understandable view to anyone even who new to dgraph just like me. Despite the fact that how it's physically stored behind.
putting facets value inside the object would give a better understandable view
I second this. Please update the docs to reflect this change in behavior or re-add the "Facets on scalar predicates" feature which was a nice touch imo. Having to manually set the facet of each corresponding node after getting the query response will definitely lead to some hacky code.
@MiLeung Facets on scalar are okay. What was changed is facets in entities or List Type https://docs.dgraph.io/query-language/#list-type
Will upcoming versions of Dgraph bring back the old behavior like?
{
"data": {
"q": [
{
"name|initial": "C",
"name": "Carol"
}
]
}
}
This new behavior is difficult to work with in examples like this

where ideally, the facets should be like
"data": {
"q": [
{
"checkouts": [
{
"uid": "0x201d3",
"lessons": [
{
"uid": "0x201ae",
"title": "ROFL",
"lessons|salePrice": 1
}
],
"total": 1,
"date": 1585021708691
}
]
}
]
}
We are still working on it.
I think if the facet is attached to the object, then let's put the facet inside the object. If it is a list of scalar values, then we can use the map.
Hi all, we have discussed facets format internally and prepared one document with different possible formats. Please checks below discuss post and provide your feedback.
https://discuss.dgraph.io/t/facets-format-in-mutation-requests-and-query-responses/6416
Most helpful comment
We are still working on it.