Query multiple UID with DQL in Python

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()

What is the issue with it?

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.

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.

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

@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?