Skip to content

Conversation

@setchy
Copy link
Member

@setchy setchy commented Dec 26, 2025

Implement GraphQL query aliasing and merging to reduce network calls and better utilize GitHub API rate limits

Sample Dataset Screenshot 2025-12-27 at 8 27 09 AM
Before - v6.14.1 release build Screenshot 2025-12-27 at 8 22 34 AM
After - #2468 + this PR Screenshot 2025-12-27 at 8 32 25 AM

For Issues, Pull Requests or Discussions, full enrichment now occurs in a single API query with a maximum query cost of 4 units

@github-actions github-actions bot added the enhancement New feature or enhancement to existing functionality label Dec 26, 2025
@setchy
Copy link
Member Author

setchy commented Dec 26, 2025

Current state of this PR is functional, but needs some further polish / refactoring, and update tests before being ready

@setchy setchy marked this pull request as draft December 26, 2025 22:39
@setchy setchy changed the title feat(api): implement merge query pattern feat(api/graphql): implement merge query pattern Dec 26, 2025
@github-actions github-actions bot removed the enhancement New feature or enhancement to existing functionality label Dec 26, 2025
@setchy setchy changed the title feat(api/graphql): implement merge query pattern feat(api): implement graphql merge query pattern Dec 29, 2025
@github-actions github-actions bot added the enhancement New feature or enhancement to existing functionality label Dec 29, 2025
@setchy setchy changed the title feat(api): implement graphql merge query pattern feat(api): implement graphql merge query pattern to reduce api call volume Dec 29, 2025
@afonsojramos afonsojramos force-pushed the feat/query-merging branch 2 times, most recently from d09207b to 02866a2 Compare December 30, 2025 02:29
afonsojramos and others added 2 commits December 30, 2025 04:05
- Add query merging infrastructure to batch multiple GraphQL queries into one
- Create BatchMergedDetailsQueryFragment for combined notification queries
- Update handlers (Discussion, Issue, PullRequest) with mergeQueryConfig
- Add INDEX suffix variable naming for merged query support
- Create getNotificationAuthor helper to handle snake_case/camelCase formats
- Guard against null URLs in notification enrichment
- Update test mocks to use nodeINDEX response format

Co-authored-by: Adam Setch <adam.setch@outlook.com>
- Remove commented-out debug code from notifications.ts
- Fix FIXME by using isAnsweredDiscussionFeatureSupported with account
- Remove unused extras field from GraphQLMergedQueryConfig type
- Add mergeQueryConfig tests for issue, pullRequest, discussion, and default handlers
- Document why integration test is skipped (complex mocking requirements)
@afonsojramos afonsojramos marked this pull request as ready for review December 30, 2025 03:28
afonsojramos
afonsojramos previously approved these changes Dec 30, 2025
@setchy
Copy link
Member Author

setchy commented Dec 30, 2025

@afonsojramos - this isn't ready yet, it's still very much a draft

@afonsojramos
Copy link
Member

Just wanted another pair of eyes! I'll keep working on this tomorrow 🙈

@setchy setchy dismissed afonsojramos’s stale review December 30, 2025 03:44

Not ready yet, I have changed I'd like to make to it still...

@setchy
Copy link
Member Author

setchy commented Dec 30, 2025

Just wanted another pair of eyes! I'll keep working on this tomorrow 🙈

What happened to my previous work on this branch, it seems you've rewrote the history and made other changes without discussion... I have local changes that I now need to untangle...

@setchy setchy marked this pull request as draft December 30, 2025 04:02
Signed-off-by: Adam Setch <adam.setch@outlook.com>
…clash in merged query

Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
…on draft PR

Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
@setchy setchy marked this pull request as ready for review January 1, 2026 03:42
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
@setchy
Copy link
Member Author

setchy commented Jan 1, 2026

After many, many, many iterations I'm now pretty happy with how the implementation has landed. It leverages the templated graphql-codegen types/documents and a builder pattern to construct the dynamic merged query.

Latest metrics below.

Sample Dataset (98 notifications) Screenshot 2025-12-31 at 6 51 33 PM
v6.14.1 REST API enrichment orchestration Screenshot 2025-12-31 at 7 02 01 PM
new GraphQL Merged Enrichment for Discussions, Issues and Pull Requests Screenshot 2025-12-31 at 7 01 31 PM

Still some unit test coverage to be added to the builder and client.

@setchy setchy requested a review from afonsojramos January 1, 2026 05:06
Signed-off-by: Adam Setch <adam.setch@outlook.com>
@setchy
Copy link
Member Author

setchy commented Jan 1, 2026

Sometime tomorrow I'll verify if this merge query approach actually is more efficient for the API Quotas / Rate Limits. If similar, this complexity may not warrant the effort to maintain...

Copy link
Member

@afonsojramos afonsojramos left a comment

Choose a reason for hiding this comment

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

In addition to inline comments, currently, all supported notifications are batched into a single query. For large notification lists, this could create extremely large queries.
Shall we consider:

  1. Setting a maximum batch size
  2. Have a way to track the complexity of the query
  3. If merged queries repeatedly fail, fall back to individual queries

Based on this, this PR seems to add a lot of complexity. Do we really wan't it? 😬

Comment on lines 319 to 329
builder.setNonIndexedVars({
includeIsAnswered: isAnsweredDiscussionFeatureSupported(
notifications[0].account,
),
firstClosingIssues: Constants.GRAPHQL_ARGS.FIRST_CLOSING_ISSUES,
firstLabels: Constants.GRAPHQL_ARGS.FIRST_LABELS,
lastComments: Constants.GRAPHQL_ARGS.LAST_COMMENTS,
lastThreadedComments: Constants.GRAPHQL_ARGS.LAST_THREADED_COMMENTS,
lastReplies: Constants.GRAPHQL_ARGS.LAST_REPLIES,
lastReviews: Constants.GRAPHQL_ARGS.LAST_REVIEWS,
});
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this assuming that notifications all belong to the same account?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's correct

The flow of notifications.ts is currently:

  • notifications/getNotifications fetches the notification list per Gitify account
  • notifications/getAllNotifications iterates over each Gitify account and base filters, enriches and detail filters

@setchy
Copy link
Member Author

setchy commented Jan 1, 2026

Sometime tomorrow I'll verify if this merge query approach actually is more efficient for the API Quotas / Rate Limits. If similar, this complexity may not warrant the effort to maintain...

Updated analysis on quota consumption below...

Note: REST and GraphQL API Quotas as independent

Configuration

  • Inbox size: 78 notifications
  • Detailed notifications: enabled
  • Measurement: delta between X-Ratelimit-Used response header per inbox refresh event
Build Tested REST API Quota Consumed GraphQL API Quota Consumed
v6.14.1 150 4
main branch 15 60
merged query pr 15 3

Copy link
Member

@afonsojramos afonsojramos left a comment

Choose a reason for hiding this comment

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

Testing looks awesome! Just some function naming proposals, but looks good overall!

setchy added 13 commits January 1, 2026 10:47
… batching vs query merging

Signed-off-by: Adam Setch <adam.setch@outlook.com>
… batching vs query merging

Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
Signed-off-by: Adam Setch <adam.setch@outlook.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 2, 2026

@setchy setchy merged commit 5917b3c into main Jan 2, 2026
14 checks passed
@setchy setchy deleted the feat/query-merging branch January 2, 2026 02:56
@github-actions github-actions bot added this to the Release 6.15.0 milestone Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or enhancement to existing functionality

Development

Successfully merging this pull request may close these issues.

3 participants