Thread
#prefect-community
    Luca Schneider

    Luca Schneider

    1 year ago
    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
    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
      }
    }
    Kevin Kho

    Kevin Kho

    1 year ago
    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
    Luca Schneider

    Luca Schneider

    1 year ago
    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 😃
    Kevin Kho

    Kevin Kho

    1 year ago
    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
    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)
    Luca Schneider

    Luca Schneider

    1 year ago
    ok but i need to make 2 calls? : one to retrieve the id and one to trigger the flow. correct ?
    Kevin Kho

    Kevin Kho

    1 year ago
    Yep!
    Luca Schneider

    Luca Schneider

    1 year ago
    ok thanks a lot