Hey everyone, I wanted to query GraphQL for all th...
# prefect-server
g
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 😫
a
If you’re utilizing the
prefect client
to execute the graphql, you can use something like the following:
Copy code
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
g
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 {
update_flow_run_state(
where: {flow_run_id: {_eq: "5e62f102-b3a9-4d7a-8a1e-bc123c5f467b"}},
_set: {state: "Skipped"}
)
}
Would love some help here too :)
mutation {
update_flow_run_state(
where: {flow_run_id: {_eq: "8561e1a2-7caa-4a14-8337-1db23dcca2d4"}},
_set: {state: "Cancelled"}
){
affected_rows
}
}
Got to this, but it isn't working.
j
@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: https://github.com/PrefectHQ/prefect/blob/master/src/prefect/client/client.py#L1263
upvote 2
👍 2
(You can also see the graphql in that route if you want to issue a raw API request yourself)
g
Thanks @Jeremiah! This worked for me 🙂