Skip to content

Auto populate pagination params on variables #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

andrewstillv15
Copy link
Contributor

Resolves #

Problem

Round out setting pagination logic such that they are truly optional params.

Solution

Checklist

  • I have run this code, and it appears to resolve the stated issue.
  • This PR does not reduce total test coverage
  • This PR has no user interface changes or has already received approval from product management to change the interface.
  • Does this change require a Terraform schema change?
    • If so what is the ticket or PR #
  • Make a changie entry that explains the customer facing outcome of this change

clientGQL.go Outdated
variables = client.InitialPageVariablesPointer()
}

if (*variables)["after"] == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There isn't a spread operator in go from what I can tell, very open to other suggestions for this.

Copy link
Collaborator

@rocktavious rocktavious Apr 24, 2025

Choose a reason for hiding this comment

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

I think the function you have is fine but for the future writing something that merges 2 maps would be more future proof.

func mergeMaps(map1, map2 map[string]any) map[string]any {
	merged := make(map[string]any)

	for key, value := range map1 {
		merged[key] = value
	}

	for key, value := range map2 {
		if _, present := merged[key]; !present {
			merged[key] = value
		}
	}

	return merged
}

Then you can just have something like

func (client *Client) PopulatePaginationParams(variables *PayloadVariables) *PayloadVariables {
	if variables == nil {
		variables = client.InitialPageVariablesPointer()
	}
	
	return mergeMaps(variables, client.InitialPageVariablesPointer())
}

@andrewstillv15 andrewstillv15 force-pushed the provide-pagination-params-if-none-provided branch from b7262e9 to 6f79364 Compare April 24, 2025 17:49
@andrewstillv15
Copy link
Contributor Author

@rocktavious I've hit all the low hanging fruit with respect to the variables == nil behaviour. There are a few (4) more spots with a bit more complexity that I can look into to but before I do, I want to make sure that the testing scope of this isn't much beyond the test cases run in the CI. These changes are non-breaking so it should be safe, but I just want to double check before continuing.

@rocktavious
Copy link
Collaborator

rocktavious commented Apr 25, 2025

@andrewstillv15 - Good to stop and check. I think most of our tests use "nil" on the client.List* methods. You'd have to do a search.

I think we potentially have some non-nil ones in some of the sub resource calls on like Service or Teams maybe.

The option that is likely WAY simpler to implement is to just put the new common.go functions under test. As long as PopulatePaginationParams has some unit tests baking its expected behaviour in different senarios into a test case (or a few) then it doesn't matter if our client.List* methods are tested with non-nil variables input.

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