# Predicate name support in GraphQL variables

**URL:** <https://discuss.dgraph.io/t/predicate-name-support-in-graphql-variables/8838>\
**Category:** Dgraph\
**Tags:** dgraph, status:accepted, kind:feature, area:querylang:vars\
**Created:** [January 17, 2018, 5:44am UTC](https://discuss.dgraph.io/t/predicate-name-support-in-graphql-variables/8838 "2018-01-17T05:44:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [January 17, 2018, 5:44am UTC](https://discuss.dgraph.io/t/predicate-name-support-in-graphql-variables/8838/1 "2018-01-17T05:44:43Z")

</div>

**Moved from GitHub [dgraph/5031](https://github.com/dgraph-io/dgraph/issues/5031)**

_Posted by_ [llonchj](https://github.com/llonchj):

Given I have a node:

```auto
<_: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.

```auto
        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

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [May 31, 2019, 7:11pm UTC](https://discuss.dgraph.io/t/predicate-name-support-in-graphql-variables/8838/2 "2019-05-31T19:11:04Z")

</div>

[campoy](https://github.com/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!

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [May 31, 2019, 7:13pm UTC](https://discuss.dgraph.io/t/predicate-name-support-in-graphql-variables/8838/3 "2019-05-31T19:13:12Z")

</div>

[llonchj](https://github.com/llonchj) _commented_ :

Cap problema @campoy! Thank you!

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [March 25, 2020, 6:22am UTC](https://discuss.dgraph.io/t/predicate-name-support-in-graphql-variables/8838/4 "2020-03-25T06:22:20Z")

</div>

[MichelDiz](https://github.com/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

```auto
query uid($name: string="test@example.com", $type: string="<type:emailAccount>"){
  uid(func:eq(name, $name)) @filter(has($type)) {
    uid
    name
  }
}

```

---

<div class="post-metadata">

**Author:** ![vitorhirota](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/vitorhirota/32/2525_2.png) [@vitorhirota](https://discuss.dgraph.io/u/vitorhirota)\
**Post date:** [August 21, 2020, 5:14pm UTC](https://discuss.dgraph.io/t/predicate-name-support-in-graphql-variables/8838/5 "2020-08-21T17:14:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![LGalatin](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/lgalatin/32/2829_2.png) [@LGalatin](https://discuss.dgraph.io/u/LGalatin)\
**Post date:** [August 21, 2020, 5:21pm UTC](https://discuss.dgraph.io/t/predicate-name-support-in-graphql-variables/8838/6 "2020-08-21T17:21:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Stefan\_Winkler](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/stefan_winkler/32/10014_2.png) [@Stefan\_Winkler](https://discuss.dgraph.io/u/Stefan_Winkler)\
**Post date:** [September 15, 2022, 7:52am UTC](https://discuss.dgraph.io/t/predicate-name-support-in-graphql-variables/8838/7 "2022-09-15T07:52:08Z")

</div>

+1 for this feature.

My usecase is reported in [Passing Sorting Criteria to Custom DQL - #3 by jdgamble555](http://discuss.hypermode.com/t/passing-sorting-criteria-to-custom-dql/17777/3)

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

```auto
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
      }
}

```
