Hi there, I’m new to prefect and GraphQL. I’m tryi...
# ask-community
l
Hi there, I’m new to prefect and GraphQL. I’m trying to trigger a flow based on the flow_name. Is there a way to chain the following GraphQL queries or do i need to send the requests consecutively ? Thanks
Copy code
query GetLatest {
  project(where: {name: {_eq: "project-test"}}) {
    flows(
      where: {name: {_eq: "flow-test"}, archived: {_eq: false}}
      order_by: {version: desc}
      limit: 1
    ) {
      id
    }
  }
}

mutation TriggerLatest {
  create_flow_run(input: {flow_id: "xxx"}) {
    id
  }
}
k
I think if you are using the interactive API, it only runs one at a time so you do need to chain these…but if you are using Python, there is a
StartFlowRun
task and
create_flow_run
task that do these for you here. You can also check the source here to see how it does it. These tasks will be easier than using the graphQL api in python
l
Hi thanks for your answer, yes I have been using the interactive api and I understand i could use the python client. But I’m designing this query for my co-workers that will run it with C#/.Net
From reading the source code, it seems that it query first the flow id before creating the flow_run
Hence I’m looking for an example of such queries chaining :)
k
Ah I understand. Yes exactly you’re on the right track 🙂
Just make sure you attach the authorization in the header, but you probably figured it out
Copy code
query = """query {flow{ name, id}}"""


url = '<https://api.prefect.io>'
r = <http://requests.post|requests.post>(url, json={'query': query}, headers={"authorization": "Bearer MY_TOKEN_HERE"})
print(r.status_code)
print(r.text)
l
ok but i need to make 2 calls? : one to retrieve the id and one to trigger the flow. correct ?
k
Yep!
l
ok thanks a lot