Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions clientGQL.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,17 @@ func (client *Client) Validate() error {
func WithName(name string) graphql.Option {
return graphql.OperationName(name)
}

func (client *Client) PopulatePaginationParams(variables *PayloadVariables) *PayloadVariables {
if variables == nil {
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())
}

(*variables)["after"] = client.InitialPageVariables()["after"]
}
if (*variables)["first"] == nil {
(*variables)["first"] = client.InitialPageVariables()["first"]
}
return variables
}
4 changes: 1 addition & 3 deletions document.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ func (client *Client) ListDocuments(variables *PayloadVariables) (*ServiceDocume
}
}

if variables == nil {
variables = client.InitialPageVariablesPointer()
}
variables = client.PopulatePaginationParams(variables)

if (*variables)["searchTerm"] == nil {
(*variables)["searchTerm"] = ""
Expand Down
5 changes: 2 additions & 3 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@ func (service *Service) GetDocuments(client *Client, variables *PayloadVariables
return nil, fmt.Errorf("unable to get 'Documents', invalid service id: '%s'", service.Id)
}

if variables == nil {
variables = client.InitialPageVariablesPointer()
}
variables = client.PopulatePaginationParams(variables)

if (*variables)["searchTerm"] == nil {
(*variables)["searchTerm"] = ""
}
Expand Down
Loading