Thread
#show-us-what-you-got
    james.lamb

    james.lamb

    2 years ago
    I've been trying to figure out how to get a
    flow_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

    nicholas

    2 years ago
    Hi @james.lamb, some small changes:
    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

    james.lamb

    2 years ago
    😱 that's cool, I didn't know you could do that! It was kind of hard to figure out which entities I'd be able to reference in queries, but I imagine that's just because I'm super new to GraphQL. Thank you!!!
    nicholas

    nicholas

    2 years ago
    😄
    james.lamb

    james.lamb

    2 years ago
    why did something like this not come up when I googled "GraphQL equivalent of inner join" 😂
    nicholas

    nicholas

    2 years ago
    The InteractiveAPI in the UI can help figure out syntax/playground your queries 🙂
    james.lamb

    james.lamb

    2 years ago
    oh cool, cool
    Jenny

    Jenny

    2 years ago
    I find Hasura's docs pretty useful for figuring out how to write GraphQL queries etc too: https://hasura.io/docs/1.0/graphql/manual/queries/index.html
    james.lamb

    james.lamb

    2 years ago
    oooooooooooooooooooo thanks!