Thread
#prefect-community
    l

    Lucas Hosoya

    7 months ago
    Hi, I'm trying to get logs from the GraphQL API but there is a limitation in the query. Is there a way to paginate the query so I can get all of the content?
    Anna Geller

    Anna Geller

    7 months ago
    You're correct, you would need to use limits and offsets to paginate through the results, e.g.
    {
      flow(
        where: {name: {_eq: "extract_load_dev"}}
        order_by: {version: desc}
        limit: 1
        offset: 1
      ) {
        id
        name
        version
      }
    }
    l

    Lucas Hosoya

    7 months ago
    Oh, thanks!
    I thought it would give an pagination id for each element just like in the REST API
    Anna Geller

    Anna Geller

    7 months ago
    It's a bit different but you can get up to 100 elements in one go. Are you on Prefect Cloud or Server? There are additional ways you can get logs from if GraphQL seems too complex for you. If you are on Cloud, on which tier are you?
    l

    Lucas Hosoya

    7 months ago
    Right now Im on Prefect Cloud using the free tier (not standard)
    Anna Geller

    Anna Geller

    7 months ago
    Thanks, that's helpful to know. In that case, Cloud only keeps one week of run history, so it should be probably quite doable to query it even without pagination? You can always filter for a specific flow ID and query flow runs and logs only for that specific flow per query
    query {
    	flow_run (where: {flow_id: {_eq: "6ce7b678-4687-4293-8d1d-ecda6c61f36d"}}){
        name
        flow_id
        flow {
          name
          id
        }
        logs {
          message
          level
          info
          created
        }
      }
    }
    Ken Nguyen

    Ken Nguyen

    6 months ago
    Hi! I wanted to follow up on this thread. Is there a way to set the
    offset
    such that it just gets the latest run’s log of that flow?
    Anna Geller

    Anna Geller

    6 months ago
    you could sort by timestamp in desc order and limit 1 to get the latest run - would this answer your question?
    Ken Nguyen

    Ken Nguyen

    6 months ago
    Oh yes that’s perfect! Would you be able to provide the syntax on how to do that?
    Actually, I was able to find examples in Slack history. Thanks for your help!
    query {
      flow_run (
        where: {flow_id: {_eq: "6ce7b678-4687-4293-8d1d-ecda6c61f36d"}}
        order_by: {state_timestamp: desc}
        limit: 1
      ){
        name
        flow_id
        flow {
          name
          id
        }
        logs {
          message
          created
        }
      }
    }