dgraph
dgraph copied to clipboard
Predicate name support in GraphQL variables
Given I have a node:
<_:1> <type:emailAccount> "" .
<_:1> <name> "[email protected]" .
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]
.
q := `
query uid($name: string)
{
uid(func:eq(name, $name)) @filter(has($type)) {
uid
}
}
`
What should be the query in order to work using $type
to call has($type)
?
Thanks
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!
Cap problema @campoy! Thank you!
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="[email protected]", $type: string="<type:emailAccount>"){
uid(func:eq(name, $name)) @filter(has($type)) {
uid
name
}
}
Github issues have been deprecated. This issue has been moved to discuss. You can follow the conversation there and also subscribe to updates by changing your notification preferences.
![drawing](https://github.com/dgraph-io/benchmarks/blob/master/images/SetNotifications.png?raw=true)
+1 for this feature.
My usecase is reported in https://discuss.dgraph.io/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.
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
}
}