Hey everyone, I wanted to query GraphQL for all th...
# prefect-server
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 😫
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
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.
@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)
Thanks @Jeremiah! This worked for me 🙂