Supports fields localization as variables when QueryWithVariables

Moved from GitHub dgo/7

Posted by AlexandreRoba:

Hi,

I’ve tried to perform a query which returns localized fields. I would like to pass the localization as variables such as:

var variables = map[string]string{
		"$local":"en:fr:.",
	}
	const q = `
{
  items(func: has(item)){
    id: uid
    short_description: title@$local.
    long_description: description@$local.
  }
}
`
	response, err := txn.QueryWithVars(ctx, q,variables)

I’m getting a lexical error when I try this.

It would make sense to be able to query with a local as variable

manishrjain commented :

Can you please file this in Dgraph?

srfrog commented :

also, how about using this instead:

var variables = map[string]string{
  "$local":"en:fr:.",
}
const q = `
{
  items(func: has(item)){
    id: uid
    short_description: title@%[1]s.
    long_description: description@%[1]s.
  }
}
`
response, err := txn.QueryWithVars(ctx, fmt.Sprintf(q, variables["$local"]))

srfrog commented :

Dgraph feature, closing here.