Skip to content

Commit f245677

Browse files
committed
improve the ToGraphQLParams function
1 parent 3f2f689 commit f245677

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

pkg/github/server.go

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,12 @@ type CursorPaginationParams struct {
281281
}
282282

283283
// ToGraphQLParams converts cursor pagination parameters to GraphQL-specific parameters.
284-
func (p CursorPaginationParams) ToGraphQLParams() (GraphQLPaginationParams, error) {
284+
func (p CursorPaginationParams) ToGraphQLParams() (*GraphQLPaginationParams, error) {
285285
if p.PerPage > 100 {
286-
return GraphQLPaginationParams{}, fmt.Errorf("perPage value %d exceeds maximum of 100", p.PerPage)
286+
return nil, fmt.Errorf("perPage value %d exceeds maximum of 100", p.PerPage)
287287
}
288288
if p.PerPage < 0 {
289-
return GraphQLPaginationParams{}, fmt.Errorf("perPage value %d cannot be negative", p.PerPage)
289+
return nil, fmt.Errorf("perPage value %d cannot be negative", p.PerPage)
290290
}
291291
first := int32(p.PerPage)
292292

@@ -295,7 +295,7 @@ func (p CursorPaginationParams) ToGraphQLParams() (GraphQLPaginationParams, erro
295295
after = &p.After
296296
}
297297

298-
return GraphQLPaginationParams{
298+
return &GraphQLPaginationParams{
299299
First: &first,
300300
After: after,
301301
}, nil
@@ -309,24 +309,13 @@ type GraphQLPaginationParams struct {
309309
// ToGraphQLParams converts REST API pagination parameters to GraphQL-specific parameters.
310310
// This converts page/perPage to first parameter for GraphQL queries.
311311
// If After is provided, it takes precedence over page-based pagination.
312-
func (p PaginationParams) ToGraphQLParams() (GraphQLPaginationParams, error) {
313-
if p.PerPage > 100 {
314-
return GraphQLPaginationParams{}, fmt.Errorf("perPage value %d exceeds maximum of 100", p.PerPage)
315-
}
316-
if p.PerPage < 0 {
317-
return GraphQLPaginationParams{}, fmt.Errorf("perPage value %d cannot be negative", p.PerPage)
312+
func (p PaginationParams) ToGraphQLParams() (*GraphQLPaginationParams, error) {
313+
// Convert to CursorPaginationParams and delegate to avoid duplication
314+
cursor := CursorPaginationParams{
315+
PerPage: p.PerPage,
316+
After: p.After,
318317
}
319-
first := int32(p.PerPage)
320-
321-
var after *string
322-
if p.After != "" {
323-
after = &p.After
324-
}
325-
326-
return GraphQLPaginationParams{
327-
First: &first,
328-
After: after,
329-
}, nil
318+
return cursor.ToGraphQLParams()
330319
}
331320

332321
func MarshalledTextResult(v any) *mcp.CallToolResult {

0 commit comments

Comments
 (0)