dgraph icon indicating copy to clipboard operation
dgraph copied to clipboard

Support GraphQL variables in subqueries

Open sboorlagadda opened this issue 8 years ago • 3 comments

GraphQL variables are used to pass values to queries and currently are only supported at the root level. Supporting GraphQL variables at sub-queries may be required for some queries where users wants to supply values that they already have in hand.

For example user can retrieve an edge between two nodes if he has UIDs, like

query q($source: string, $target: string) {
    edge(func: uid($source)) {
        visited @filter(uid($target)) {
            uid
        }
    }
}

Currently Dgraph supports GraphQL variables at root query edge and not at sub-query visited.

Though as a work-around, user can introduce a DGraph variable to query edge between two known nodes, like

query q($source: string, $target: string) {
    var (func: uid($target)) {
        target as uid
    }
    edge(func: uid($source)) {
        visited @filter(uid(target)) {
            uid
        }
    }
}

sboorlagadda avatar Feb 04 '18 23:02 sboorlagadda

This should be fixed with 4d6a6077343570518cbe247fa1fbf9320731b09b.

pawanrawal avatar Apr 26 '18 01:04 pawanrawal

hi, i found a problem with query like this:

query withvar($a:string, $b:bool) {

query(func:uid($a)) {

candidate_school @facets(eq(on_edu,$b)) @groupby(name) {

  count(uid)
}

} }

it doesn't have any result return, but when i use query like this:

` { query(func:uid(0x998a17)) {

candidate_school @facets(eq(on_edu,false)) @groupby(name) {

  count(uid)

}

} }`

it has result.

it seems that queryWithVars has a problem when query vars in facets. @pawanrawal @sboorlagadda

refer : https://discuss.dgraph.io/t/query-and-querywithvars/2796/9

shanghai-Jerry avatar Jul 05 '18 08:07 shanghai-Jerry

Can you file a new issue? I prefer not to re-open closed issues.

manishrjain avatar Jul 09 '18 20:07 manishrjain