https://prefect.io logo
j

Joshua Greenhalgh

04/21/2022, 3:20 PM
I promise to stop being annoying today!! After this lol Is it possible to write a single mutation to delete every flow in a given project?
😂 1
k

Kevin Kho

04/21/2022, 3:20 PM
Do you wanna just use the UI to delete the project is one go?
j

Joshua Greenhalgh

04/21/2022, 3:21 PM
No want the project to stay just be empty - I have a "dev" project which I want to be able to easily clean up
k

Kevin Kho

04/21/2022, 3:22 PM
The answer though is I don’t think it’s a single mutation. You really need to get all the flows is one query and then loop through and delete them
j

Joshua Greenhalgh

04/21/2022, 3:22 PM
So this gives me all the IDs;
Copy code
{
  flow(where: {project: {name: {_eq: "dev"}}}) {
    id
  }
}
Can you pass that into the delete_flow mutation somehow?
Ok that makes sense - don't really understand what graphql can do - so need to drop into python or something using the result from that first query?
k

Kevin Kho

04/21/2022, 3:25 PM
So you do something like:
Copy code
query = """
{
  flow(where: {project: {name: {_eq: "dev"}}}) {
    id
  }
}
"""

from prefect.client import Client
client = Client()
client.graphql(query)
and you can print the return. It’s JSON and then you can pull the ids from the
data
field I think and then make a new query
Copy code
query = """
mutation {
  deleteFlow(input: "flow_id") {
    success
  }
}
"""
🙌 1
a

Anna Geller

04/21/2022, 3:25 PM
you could delete the project and then create it again - you do it in like 2 clicks in the UI and you're done 😄 any reason why you want to do it from GraphQL?
k

Kevin Kho

04/21/2022, 3:26 PM
I think that doesn’t work smoothly @Anna Geller, because the project deletion is a soft delete so you can’t recreate the same name until a few hours later when the delete actually pushes through
a

Anna Geller

04/21/2022, 3:27 PM
oh I see, TMYK thanks. btw, Joshua, there is also an option to archive a flow - just in case you may want to keep the run history for auditability
j

Joshua Greenhalgh

04/21/2022, 3:30 PM
cos I don't like clicking firstly lol - I want to be able to run it from the terminal - they are completely throw away its just going to be a place for devs to test things they can't do easily locally before merging into master and then being deployed to a prod project
I think the loopy way is perfect
@Anna Geller I also love to shave yaks
12 Views