https://prefect.io logo
l

Lucas Hosoya

02/21/2022, 12:54 PM
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?
a

Anna Geller

02/21/2022, 1:11 PM
You're correct, you would need to use limits and offsets to paginate through the results, e.g.
Copy code
{
  flow(
    where: {name: {_eq: "extract_load_dev"}}
    order_by: {version: desc}
    limit: 1
    offset: 1
  ) {
    id
    name
    version
  }
}
1
l

Lucas Hosoya

02/21/2022, 1:23 PM
Oh, thanks!
I thought it would give an pagination id for each element just like in the REST API
a

Anna Geller

02/21/2022, 1:53 PM
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

02/21/2022, 1:56 PM
Right now Im on Prefect Cloud using the free tier (not standard)
a

Anna Geller

02/21/2022, 2:36 PM
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
Copy code
query {
	flow_run (where: {flow_id: {_eq: "6ce7b678-4687-4293-8d1d-ecda6c61f36d"}}){
    name
    flow_id
    flow {
      name
      id
    }
    logs {
      message
      level
      info
      created
    }
  }
}
k

Ken Nguyen

03/23/2022, 12:09 AM
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?
a

Anna Geller

03/23/2022, 12:26 AM
you could sort by timestamp in desc order and limit 1 to get the latest run - would this answer your question?
k

Ken Nguyen

03/23/2022, 2:00 AM
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!
Copy code
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
    }
  }
}
🙌 1
47 Views