https://prefect.io logo
r

Richard Hughes

12/17/2020, 6:36 PM
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

Dylan

12/17/2020, 6:38 PM
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

Richard Hughes

12/17/2020, 6:43 PM
okay, let me see if I can find the doc on running python graphql
d

Dylan

12/17/2020, 6:45 PM
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

Richard Hughes

12/17/2020, 7:04 PM
How does this work?
($id: UUID!)
"1234-1234-1234-1235": UUID!"
d

Dylan

12/17/2020, 7:06 PM
That’s a GraphQL Variable
Copy code
mutation DeleteFlow($id: UUID!) {
  delete_flow(input: {flow_id: $id}) {
    success
  }
}
that’s the proper mutation