GraphQL API python client syntax question: I'm tr...
# prefect-community
v
GraphQL API python client syntax question: I'm trying to query a flow run by filtering on the value of the parameters. I cannot figure out how to pass a json blob object to the query using python. When I use json.dumps method python produces a string and as a result I get a bad request error. Not sure how to create a jsonb type parameters object and I was hoping someone might be able to point me in the right direction.
discourse 1
k
I made this page today. I think it will show you
Ah wait no this is a bit different. Can you show me your current code?
This is a good example of that
v
It looks like I had some syntax errors in my client.graphql call. Once I fixed that a regular python json string fixed the issue. Here's the sample code for posterity.
Copy code
client = prefect.Client()
query = """
        #Get latest flow run by flow name, project name combination, and parameters
        #params is a JSON object and the query does a contains check
        query($flow_name: String!, $project_name: String!, $params: jsonb!){
            flow_run(
                where: {
                    flow: {
                        name: {_eq: $flow_name}
                        project: {
                            name: {_eq: $project_name}
                        }
                    }
                    state: {_eq: "Success"},
                    parameters: {_contains: $params}
                } 
                order_by : {end_time: desc} 
                limit : 1
            ){
                id
                version
                end_time
                name
                state
                task_runs {
                    id
                    state
                    task {
                        id
                        name
                    }
                }
                parameters
            }
        }
"""
variables = {"flow_name": flow_name, "project_name": project_name, "params": params}
flow_run_query = client.graphql(query=query, variables=variables)
👍 1
a
Thanks for sharing, Vaikath! I cross-posted here
👍 1