@amanmangal
In this example - pydgraph/simple.py at master · dgraph-io/pydgraph · GitHub
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 !!
Shouldn’t you have to specify type of b
variable in the first query, that it is integer?
amandalmia14:
$b: integer
I missed this part in my query, but still I am getting the same error.
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.
@amanmangal even after doing the changes as you suggested. Still I am getting below errors.
raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
status = StatusCode.UNKNOWN
details = "Expected value inside @recurse() for key: depth."
debug_error_string = "{"created":"@1565942227.567215716","description":"Error received from peer ipv4:132.186.173.33:9080","file":"src/core/lib/surface/call.cc","file_line":1052,"grpc_message":"Expected value inside @recurse() for key: depth.","grpc_status":2}"
>
amanmangal
(Aman Mangal)
August 19, 2019, 12:20am
7
Seems like something is not correct with arguments to recurse. Could you share the query?
@amanmangal
"""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}}
metric_used_in {name@en normalizes_to {name@en}}
~metric_used_in {name@en normalizes_to {name@en}}
}
}"""
keywords = "policy"
variables = {'$a': keywords, '$b': '5'}
res = client.txn().query(query, variables=variables)
amanmangal
(Aman Mangal)
August 22, 2019, 2:45am
9
We currently do not support depth value to be passed as a variable argument. Feel free to raise an issue on GitHub, this may be useful to support.
@recurse(depth: $b)
$b needs to be replaced with actual value here.
@amanmangal .
Sure will do that.
Earlier I was replacing a number with the variable but it won’t solve my problem as it will result to hard-coded values to which I don’t want.
Is there any workaround?
Thanks
amanmangal
(Aman Mangal)
August 22, 2019, 4:55am
11
I think for now you just have to use javascript (or any other language for that matter) to format the query.
1 Like