Hi, I am hoping to find some help writing a mutat...
# prefect-community
r
Hi, I am hoping to find some help writing a mutation to delete flows from a query. Any guidance on this so far what I can figure out from lack of understanding of the graphql
Copy code
mutation {
  delete_flow(input: 
  
    query {
  flow 
  (where: {name: {_eq: "MyFlowToDelete" }})
    {

    id
  }
}
    ) {
    success,
    error
  }
}
d
Hi @Richard Hughes, The mutation doesn’t accept another query as a parameter. You’ll have to have an intermediate action that grabs the ids from the first query and passes them to the mutation
Something like (in very pseudo python code)
r
okay, let me see if I can find the doc on running python graphql
d
Copy code
from prefect import Client
from prefect.engine.state import Failed

c = Client()


flows = c.graphql(
    query="""
    query {
  flow(where: {name: {_eq: "My Flow's Name"}}) {
    id
  }
}"""
)
flows = flows.get("data").get("task_run")
print(flows)

for flow in flows:
    print(flow)
    id = flow.get("id")
    result = c.graphql(
        query="""mutation DelteFlow($id: UUID!){ delete_flow(input: {id: $id}) { success } }""",
        variables={"id": "1234-1234-1234-1235"},
    )
I haven’t run that code (like I said, pseudocode) but that’s the general idea of what you’re looking for
You can refine the mutation using the interactive API
r
How does this work?
($id: UUID!)
"1234-1234-1234-1235": UUID!"
d
That’s a GraphQL Variable
Copy code
mutation DeleteFlow($id: UUID!) {
  delete_flow(input: {flow_id: $id}) {
    success
  }
}
that’s the proper mutation