Predicate name support in GraphQL variables

Moved from GitHub dgraph/5031

Posted by llonchj:

Given I have a node:

<_:1> <type:emailAccount> "" .
<_:1> <name> "" .

I want to be able to retrieve the uid given the name and has(<type:emailAccount>).

I am trying to build the query using QueryWithVars and the golang api.

The query works with a hardcoded $type variable.

        variables := map[string]string{
    		"$name": Name,
    		// "$type": Type,
    	q := `
    	query uid($name: string)
    		uid(func:eq(name, $name)) @filter(has(<type:emailAccount>)) {
    	resp, err := txn.QueryWithVars(ctx, q, variables)
    	if err != nil {
    		return "", err

If i try to use $type as variable, returns the error: rpc error: code = Unknown desc = Got empty attr for function: [has].

What should be the query in order to work using $type to call has($type)?


1 Like

campoy commented :

Wow, this is an old issue and doesn’t seem like it should have been left open for so long.
Sorry about that, @llonchj!
I’ll add to the possible list of improvements to the query language but I can’t promise it will make it into our roadmap any time soon.


llonchj commented :

Cap problema @campoy! Thank you!

MichelDiz commented :

I have moved this issue to Dgraph as this is a bug in Dgraph’s query parser. So, it is not related to Dgo.

Reproducible with

query uid($name: string="", $type: string="<type:emailAccount>"){
  uid(func:eq(name, $name)) @filter(has($type)) {

I’m sorry, I’m a bit loss with this going from/to github issues. The issue is closed there, but it’s not fixed. Is that right?

You are correct: the issue is closed in Github only because we are not accepting issues in Github anymore. Please check back here for progress on this issue.