@lang directive. Info on resolved language

Moved from GitHub dgraph/3801

Posted by vilarfg:

Experience Report

What you wanted to do

When I write a query using the @lang directive, I don’t receive info on the locale of the result.
Example query:

{
    q(func: allofterms(name@en, "Farhan Akhtar")) {
        name@hi
        name@en

        director.film {
            name@ru:hi:en
            name@en
            name@hi
            name@ru
        }
    }
}

Example result (only the bit about director.film, for brevity):

"director.film": [
    {
        "name@ru:hi:en": "दिल चाहता है"
    }
]

I can see it’s been resolved to hindi, but it’s not labeled as hindi. It’s labeled as ru:hi:en

Why that wasn’t great, with examples

It would be nicer to have an indication on the language of the result (and ideally the prompt as well). Like:

"director.film": [
    {
        "name@hi": "दिल चाहता है"
    }
]

or

"director.film": [
    {
        "name@ru:hi:en": { "hi": "दिल चाहता है"}
    }
]

PS: I’ve been instructed to CC @campoy on this one

campoy commented :

This is an interesting request, indeed.

We could consider changing the returned field so you’d get name@hi if you ended up getting the hindi result. That said, that would cause issues in your example as you’d get two fields with the same name.

For now, wouldn’t asking for each language separately be enough?
In this case, you do exactly that which allows you to see the three languages separately and decide which one you’d like to use.

Is that workaround not enough for some of your needs? Tell me more, please.