james.lamb
07/20/2020, 3:19 PMflow_group_id
from Prefect Cloud, given a project name and flow name. As far as I understand from this thread, the combination of project name, flow name, and the tenant I'm auth'd as should be enough to uniquely identify a flow_group
. This is the first time I've ever used GraphQL so if anyone has done this or has a better recommendation, I'd welcome it! This was my solution:
from prefect.client import Client
def get_flow_group_id(flow_name, project_name) -> str:
"""
Get the `flow_group_id` for a flow with a given
name, from a given Prefect Cloud project.
"""
client = Client()
query = """
query {
flow(
where: {
name: { _eq: "%s" }
}
) {
id
name
flow_group_id
project_id
}
project(
where: {
name: { _eq: "%s" }
}
) {
id
name
}
}
""" % (flow_name, project_name)
result = client.graphql(query)
project_id = result["data"]["project"][0]["id"]
flow_group_id = [
flow for flow in
result["data"]["flow"]
if flow["project_id"] == project_id
][0]["flow_group_id"]
return flow_group_id
nicholas
query {
flow(where: {
name: {_eq: "%s"}
project: { name : {_eq: "%s"}}
}) {
id
flow_group_id
}
}
Should get you the flow group id as you've described.james.lamb
07/20/2020, 3:25 PMnicholas
james.lamb
07/20/2020, 3:26 PMnicholas
james.lamb
07/20/2020, 3:27 PMJenny
07/20/2020, 3:32 PMjames.lamb
07/20/2020, 3:50 PM