Ganesh Kalyansundaram

03/03/2021, 2:54 PM
Hey everyone, I wanted to query GraphQL for all the flow runs IDs that have failed. How would I do this? Is there a Prefect Python API that does something similar or do I have to use GraphQL? Would be nice if someone could help me with the GraphQL Query 😫

Alex Cano

03/03/2021, 3:09 PM
If you’re utilizing the
prefect client
to execute the graphql, you can use something like the following:
from prefect.client import Client
from prefect.utilities.graphql import with_args

# Initialize however you need to with any appropriate args
client = Client()
query = {
    "query": {
        with_args("flow_run", {"where": {"state": {"_eq": "Failed"}}}): {"id": True}

result = client.graphql(query)
:upvote: 3
🙌 1

Ganesh Kalyansundaram

03/03/2021, 3:29 PM
Thanks a ton @Alex Cano! This worked for us 😃
Follow up question. I want to iterate over each of the flow run id's and set the state to "Skipped". Played around a bit and got to this, but it didn't work.
mutation {
where: {flow_run_id: {_eq: "5e62f102-b3a9-4d7a-8a1e-bc123c5f467b"}},
_set: {state: "Skipped"}
Would love some help here too :)
mutation {
where: {flow_run_id: {_eq: "8561e1a2-7caa-4a14-8337-1db23dcca2d4"}},
_set: {state: "Cancelled"}
Got to this, but it isn't working.


03/03/2021, 4:01 PM
@Ganesh Kalyansundaram the route you’re calling is exposed by hasura and goes directly to the database, avoiding the Prefect API. You may want to use the builtin client route:
:upvote: 2
👍 2
(You can also see the graphql in that route if you want to issue a raw API request yourself)

Ganesh Kalyansundaram

03/09/2021, 9:26 AM
Thanks @Jeremiah! This worked for me 🙂