Hi, I'm trying to get logs from the GraphQL API bu...
# ask-community
l
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
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
Oh, thanks!
I thought it would give an pagination id for each element just like in the REST API
a
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
Right now Im on Prefect Cloud using the free tier (not standard)
a
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
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
you could sort by timestamp in desc order and limit 1 to get the latest run - would this answer your question?
k
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
105 Views