Skip to content

Conversation

albertodonato
Copy link
Contributor

what

use pagination with the cursor for query to get policy collection mappings

why

handle the case where the desired entry is not within first page of results

testing

acceptance tests and tested in sandbox

docs

n/a

### what

use pagination with the cursor for query to get policy collection mappings

### why

handle the case where the desired entry is not within first page of results

### testing

acceptance tests and tested in sandbox

### docs

n/a
@albertodonato albertodonato requested a review from a team as a code owner June 18, 2025 07:16
Copy link

@jtroup jtroup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are not blocking.

if !query.PolicyCollection.PolicyMappings.PageInfo.HasNextPage {
return nil, NotFound{"Policy collection mapping not found"}
}
cursor = query.PolicyCollection.PolicyMappings.PageInfo.EndCursor
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albertodonato I haven't checked but am trusting you that this DTRT when there's < 100 results in total 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah when there's < 100 results, HasNextPage is false, so it would exit earlier.

} `graphql:"policyCollection(uuid: $uuid)"`
}
cursor := ""
for {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albertodonato The unbounded forever loop which only ends on the API tell us it's done or giving us an error makes me twitch a little. I don't know that there's a better way and it's definitely not blocking, just idle musing on my part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way the connection protocol works is really meant to be unrolled page by page. It does have a total attribute that we could use to know ahead how many entries are there, but it could in theory become inconsistent if entries are added/removed between calls, so we'd have to have additional logic around it.

}
cursor := ""
for {
var query struct {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albertodonato I was surprised to see this struct inline inside the for loop; I don't know if that's just normal/idiomatic for go, but it makes for quite deep indentation/nesting. Again, just unblocking commentary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we can actually move the query and variables definition outside of the loop, since they don't really depend on the entry. Updated

@albertodonato albertodonato force-pushed the ack/policy-collection-mapping-use-cursor branch from 83d409a to 765a789 Compare June 19, 2025 10:28
@albertodonato albertodonato merged commit 523fc2e into main Jun 19, 2025
6 checks passed
@albertodonato albertodonato deleted the ack/policy-collection-mapping-use-cursor branch June 19, 2025 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants