Configuring "depth" in the variables, when passing through the query


(Aman) #1

@amanmangal

In this example - https://github.com/dgraph-io/pydgraph/blob/master/examples/simple/simple.py

At the method,

def query_data(client):

you have mentioned variables = {'$a': 'Alice'}, but is it possible to pass multiple data, like depth along with the name?

query = """query get_all($a: string, $b: integer) { get_all(func: anyoftext(name@en, $a))@recurse(depth: $b) {
        uid
        name@en
        normalizes_to {name@en normalizes_to {name@en}}
        ~normalizes_to {name@en normalizes_to {name@en}
     }
variables = {'$a': keywords, '$b': 5}

where keywords is a list of words and depth is an integer.
If I do that I am getting an error, as

Exception: Values and keys in variable map must be strings

If I hard code in the query,

query = """query get_all($a: string) { get_all(func: anyoftext(name@en, $a))@recurse(depth: 5) {
        uid
        name@en
        normalizes_to {name@en normalizes_to {name@en}}
        ~normalizes_to {name@en normalizes_to {name@en}
     }
variables = {'$a': keywords}

It works !!


(Aman Mangal) #2

Shouldn’t you have to specify type of b variable in the first query, that it is integer?


(Aman) #4

I missed this part in my query, but still I am getting the same error.


(Aman Mangal) #5
query = """query get_all($a: string, $b: int) { get_all(func: anyoftext(name@en, $a))@recurse(depth: $b) {
        uid
        name@en
        normalizes_to {name@en normalizes_to {name@en}}
        ~normalizes_to {name@en normalizes_to {name@en}
     }
variables = {'$a': keywords, '$b': '5'}

You have to use type as int, and the values in the map are always string. We parse them internally based on the expected type.