Predicate name support in GraphQL variables

Moved from GitHub dgraph/5031

Posted by llonchj:

Given I have a node:

<_:1> <type:emailAccount> "" .
<_:1> <name> "test@example.com" .

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>)) {
    		  uid
    		}
    	  }
    	`
    	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)?

Thanks

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.

Thanks!

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="test@example.com", $type: string="<type:emailAccount>"){
  uid(func:eq(name, $name)) @filter(has($type)) {
    uid
    name
  }
}

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.

+1 for this feature.

My usecase is reported in Passing Sorting Criteria to Custom DQL - #3 by jdgamble555

In short, I’d like to pass custom filtering or sorting criteria to a DQL query.

POST http://localhost:8080/query
Content-Type: application/dql

query q($p : string = "Person.firstName", $terms: string = "Harry", $orderby: string = "Person.lastName") {
      queryPersonCustom(func: anyofterms($p, $terms), orderasc: $orderby) {
        id : uid
        firstName : Person.firstName
        lastName : Person.lastName
      }
}