I am trying to pull multiple UID via DQL with Python.
I’m not having much luck and I tried many different approaches.
This is what I currently have.
def get_games(self):
games = {'$games': "[0x1fbd2, 0x1fbd4]"}
query = """
query games($games: string) {
query (func: uid($games)) {
uid
Game.start_date
Game.end_date
}
}
"""
try:
txn = self.dgraph_client.txn()
response = txn.query(query=query, variables=games)
return json.loads(response.json)['games']
except Exception as e:
log.error(e)
finally:
txn.discard()
MichelDiz
(Michel Diz)
February 22, 2021, 2:42am
2
What is the issue with it?
amaster507
(Anthony Master)
February 22, 2021, 2:47am
3
I think it should be:
games = {'games': "[0x1fbd2, 0x1fbd4]"}
I believe it works like regular GraphQL vars. The dollar sign is used internal in the query to reference the variable, but externally the variable is passed as an object without the dollar sign.
It doesn’t work without the $ and examples say to use it.
It doesn’t work. I get errors everyway I have tried formatting it. I’m trying to return specific records by UID (more than one) using DQL and Python. There are no examples, but I have tried 10 different ways using different bits and pieces.
amaster507
(Anthony Master)
February 22, 2021, 3:51am
6
Sorry, I was wrong. I am still rough on my DQL syntax. Tried to lend some helpful discussion which often leads to a resolution, not this time.
MichelDiz
(Michel Diz)
February 22, 2021, 4:00am
7
It should work. It might be something in the py client. I’ll ping someone (Maybe @chewxy could help to troubleshoot or point the right engineer)
1 Like
Anurag
(Anurag)
February 22, 2021, 7:40am
8
@billybobthorton
Took a quick look at the query and it works fine on my system. I tested the below query on Pydgraph 20.03:
def query(client):
query = """query q($id : string){
q2(func: uid($id) ){
name
uid
}
}"""
variables = {"$id": "[1, 2]"}
try:
response = client.txn().query(query=query, variables=variables)
print(json.loads(response.json))
return json.loads(response.json)
except Exception as e:
print(e)
finally:
client.txn().discard()
Could you share pydgraph version and the error message you get?