Skip to content

Conversation

@Piyushrathoree
Copy link
Collaborator

Proposed change

Resolves #2121

added Id field in the frontend graphQL queries to resolved apollo error.

Checklist

  • I've read and followed the contributing guidelines.
  • I've run make check-test locally; all checks and tests passed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 31, 2025

Summary by CodeRabbit

  • New Features

    • Snapshot details now show richer project stats (stars, forks, contributors, activity level, repository count).
    • Consistent IDs added across contributors, issues, pull requests, releases, milestones, admins, mentors, repositories, projects, chapters, committees, organizations, sessions, and API keys to improve item consistency and linking across the app.
  • Tests

    • Updated tests to reflect the new IDs and additional snapshot project fields.

Walkthrough

Adds id fields to many frontend GraphQL queries and mutations, adds id to RepositoryContributor model/node and resolver, and updates tests; snapshot queries also expand newProjects with additional non-id fields. No exported names, inputs, or control flow were changed.

Changes

Cohort / File(s) Summary of Changes
API Keys
frontend/src/server/queries/apiKeyQueries.ts
Add id to GET_API_KEYS apiKeys and CREATE_API_KEY apiKey selections.
Auth
frontend/src/server/queries/authQueries.ts
Add id to logoutUser and githubAuth.user selections.
Chapter & Committee
frontend/src/server/queries/chapterQueries.ts, frontend/src/server/queries/committeeQueries.ts
Add id to chapter/committee, topContributors, and metadata queries.
Home
frontend/src/server/queries/homeQueries.ts
Add id to multiple top-level lists and nested author.id selections in GetMainPageData.
Modules & Programs
frontend/src/server/queries/moduleQueries.ts, frontend/src/server/queries/programsQueries.ts
Add id to mentor/admin selections across related queries.
Organization
frontend/src/server/queries/organizationQueries.ts
Add id to organization, repositories (and their organization), topContributors, recent issues/PRs/releases/milestones and their authors; metadata adds organization.id.
Project(s)
frontend/src/server/queries/projectQueries.ts, frontend/src/server/queries/projectsHealthDashboardQueries.ts
Add id to project, health metrics list/details, repositories, topContributors, and authors in recent items; remove a duplicated id in health metrics selection.
Repository
frontend/src/server/queries/repositoryQueries.ts
Add id to repository, organization, project, lists (issues/PRs/releases/milestones) and their authors; metadata adds repository.id.
Snapshots
frontend/src/server/queries/snapshotQueries.ts
Add id to snapshot(s), newRelease, newProject, newChapter, and nested topContributors; expand newProjects selection with additional fields (key, name, summary, starsCount, forksCount, contributorsCount, level, isActive, repositoriesCount).
User
frontend/src/server/queries/userQueries.ts
Add id to user (leader/data/metadata), recent items, and top contributed repositories (and nested organization).
Backend: RepositoryContributor
backend/apps/github/models/repository_contributor.py, backend/apps/github/api/internal/nodes/repository_contributor.py, backend/apps/github/api/internal/queries/repository_contributor.py
Expose id on model projection; add id field to RepositoryContributorNode and populate id in top_contributors resolver nodes.
Backend Tests
backend/tests/apps/github/api/internal/queries/repository_contributor_test.py, backend/tests/apps/github/models/repository_contributor_test.py
Update mock contributor data to include id fields to match new shape.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Add id to frontend server GraphQL queries (#2121)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Expanded non-id fields in GET_SNAPSHOT_DETAILS (frontend/src/server/queries/snapshotQueries.ts) Adds multiple additional fields (key, name, summary, starsCount, forksCount, contributorsCount, level, isActive, repositoriesCount) beyond the linked issue's stated objective of adding only id.

Possibly related PRs

Suggested labels

backend-tests, frontend-tests

Suggested reviewers

  • arkid15r
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
frontend/src/server/queries/snapshotQueries.ts (1)

63-70: Rename metadata GraphQL operation to avoid name collision

Rename the GraphQL operation in GET_SNAPSHOT_DETAILS_METADATA to GetSnapshotDetailsMetadata to ensure each operation name is unique.

 export const GET_SNAPSHOT_DETAILS_METADATA = gql`
-  query GetSnapshotDetails($key: String!) {
+  query GetSnapshotDetailsMetadata($key: String!) {
     snapshot(key: $key) {
       id
       title
     }
   }
 `
frontend/src/server/queries/organizationQueries.ts (1)

109-118: Rename duplicate GraphQL operation name
In frontend/src/server/queries/organizationQueries.ts, both GET_ORGANIZATION_DATA and GET_ORGANIZATION_METADATA use query GetOrganization, which will collide at runtime. Change the metadata query’s operation name to something unique, for example:

 export const GET_ORGANIZATION_METADATA = gql`
-  query GetOrganization($login: String!) {
+  query GetOrganizationMetadata($login: String!) {
     organization(login: $login) {
       id
       description
       login
       name
     }
   }
 `
frontend/src/server/queries/userQueries.ts (1)

3-12: Rename GraphQL operation names to match constants
In frontend/src/server/queries/userQueries.ts, update each query GetUser to a unique name that mirrors its export, e.g.:

export const GET_LEADER_DATA = gql`
-  query GetUser($key: String!) {
+  query GetLeaderData($key: String!) {
     user(login: $key) {
       id
       avatarUrl
       login
       name
     }
   }
`

export const GET_USER_DATA = gql`
-  query GetUser($key: String!) {
+  query GetUserData($key: String!) {
     …
   }
`

export const GET_USER_METADATA = gql`
-  query GetUser($key: String!) {
+  query GetUserMetadata($key: String!) {
     user(login: $key) {
       id
       bio
       login
       name
     }
   }
`

Prevents codegen/type collisions and aids debugging.

🧹 Nitpick comments (8)
frontend/src/server/queries/homeQueries.ts (1)

6-6: Broad ID coverage — looks good.

This should stabilize list rendering keys and Apollo normalization for home widgets.

Consider extracting a shared author fragment (if your schema exposes a common interface/type for authors) to remove repetition across issues/PRs/releases/milestones.

Also applies to: 16-16, 24-24, 32-32, 38-41, 52-55, 66-69, 81-81, 95-95, 106-109

frontend/src/server/queries/repositoryQueries.ts (1)

6-6: Repository graph selections now include stable IDs — LGTM.

IDs on repository, issues, releases, recentMilestones, topContributors, recentPullRequests, and nested author objects align with Apollo best practices.

If multiple queries repeat author { id avatarUrl login name }, consider a fragment to DRY them up when the underlying type is shared.

Also applies to: 14-17, 31-31, 35-35, 40-43, 60-63, 77-77, 83-86, 102-102

frontend/src/server/queries/projectQueries.ts (1)

31-44: Optional: Add ids for list items and repository.organization for full normalization.
Helps Apollo identify list items and nested orgs, reducing cache warnings/duplicates.

       recentIssues {
+        id
         author {
           id
           avatarUrl
           login
           name
           url
         }
         createdAt
         organizationName
         repositoryName
         title
         url
       }
       recentReleases {
+        id
         author {
           id
           avatarUrl
           login
           name
         }
         name
         organizationName
         publishedAt
         repositoryName
         tagName
         url
       }
       repositories {
         id
         contributorsCount
         forksCount
         key
         name
         openIssuesCount
         organization {
+          id
           login
         }
         starsCount
         subscribersCount
         url
       }
       recentMilestones(limit: 5) {
+        id
         author {
           id
           avatarUrl
           login
           name
         }
         title
         openIssuesCount
         closedIssuesCount
         repositoryName
         organizationName
         createdAt
         url
       }
       recentPullRequests {
+        id
         author {
           id
           avatarUrl
           login
           name
         }
         createdAt
         organizationName
         repositoryName
         title
         url
       }

Also applies to: 45-58, 80-94, 95-107, 66-69

frontend/src/server/queries/moduleQueries.ts (1)

40-44: Optional: Normalize “user” shapes via fragments to reduce duplication and drift.
If mentors/admins share the same GraphQL type, consider a common fragment.

Example fragment (add once in a shared queries file or alongside these docs):

export const USER_BASIC_FIELDS = gql`
  fragment UserBasicFields on User {
    id
    login
    name
    avatarUrl
  }
`

Then use:

       mentors {
-        id
-        login
-        name
-        avatarUrl
+        ...UserBasicFields
       }

Note: Only apply if mentors/admins are of type User; otherwise keep as-is.

Also applies to: 73-77

frontend/src/server/queries/programsQueries.ts (1)

54-58: Optional: Consider a shared User fragment to keep selections consistent across modules.

Example:

export const USER_BASIC_FIELDS = gql`
  fragment UserBasicFields on User {
    id
    login
    name
    avatarUrl
  }
`

And replace repeated fields with ...UserBasicFields in admins/mentors blocks where the type is User.

Also applies to: 77-81, 108-112

frontend/src/server/queries/snapshotQueries.ts (1)

29-34: Deduplicate repeated contributor selections with a fragment (optional).

Same fields for topContributors appear multiple times. Consider a fragment for maintainability.

+const CONTRIBUTOR_BASIC = gql`
+  fragment ContributorBasic on User {
+    id
+    avatarUrl
+    login
+    name
+  }
+`;
 ...
-        topContributors {
-          id
-          avatarUrl
-          login
-          name
-        }
+        topContributors { ...ContributorBasic }
 ...
-        topContributors {
-          id
-          avatarUrl
-          login
-          name
-        }
+        topContributors { ...ContributorBasic }

Also applies to: 45-49

frontend/src/server/queries/organizationQueries.ts (1)

35-40: Use an author fragment to DRY repeated fields (optional).

author has the same four fields in three places; consider a fragment.

const AUTHOR_BASIC = gql`
  fragment AuthorBasic on User {
    id
    avatarUrl
    login
    name
  }
`;

Then replace author blocks with { ...AuthorBasic }.

Also applies to: 50-54, 65-69

frontend/src/server/queries/userQueries.ts (1)

53-66: Optional: introduce fragments for repository and user basics.

Repeated blocks (repository basics and user basics) can use shared fragments to reduce drift and ease future changes.

Also applies to: 68-85

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7cd6d44 and 75ee1f5.

📒 Files selected for processing (13)
  • frontend/src/server/queries/apiKeyQueries.ts (2 hunks)
  • frontend/src/server/queries/authQueries.ts (2 hunks)
  • frontend/src/server/queries/chapterQueries.ts (3 hunks)
  • frontend/src/server/queries/committeeQueries.ts (3 hunks)
  • frontend/src/server/queries/homeQueries.ts (7 hunks)
  • frontend/src/server/queries/moduleQueries.ts (3 hunks)
  • frontend/src/server/queries/organizationQueries.ts (6 hunks)
  • frontend/src/server/queries/programsQueries.ts (4 hunks)
  • frontend/src/server/queries/projectQueries.ts (10 hunks)
  • frontend/src/server/queries/projectsHealthDashboardQueries.ts (3 hunks)
  • frontend/src/server/queries/repositoryQueries.ts (5 hunks)
  • frontend/src/server/queries/snapshotQueries.ts (4 hunks)
  • frontend/src/server/queries/userQueries.ts (5 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-08-31T13:47:15.832Z
Learnt from: rudransh-shrivastava
PR: OWASP/Nest#2155
File: frontend/src/server/queries/programsQueries.ts:81-81
Timestamp: 2025-08-31T13:47:15.832Z
Learning: In frontend/src/server/queries/programsQueries.ts, GET_PROGRAM_DETAILS and GET_PROGRAM_ADMIN_DETAILS are two separate queries serving different purposes: GET_PROGRAM_DETAILS fetches comprehensive program information while GET_PROGRAM_ADMIN_DETAILS fetches only admin-related details.

Applied to files:

  • frontend/src/server/queries/programsQueries.ts
  • frontend/src/server/queries/moduleQueries.ts
📚 Learning: 2025-08-31T13:47:15.832Z
Learnt from: rudransh-shrivastava
PR: OWASP/Nest#2155
File: frontend/src/server/queries/programsQueries.ts:81-81
Timestamp: 2025-08-31T13:47:15.832Z
Learning: In frontend/src/server/queries/programsQueries.ts, GET_PROGRAM_DETAILS and GET_PROGRAM_ADMIN_DETAILS are two separate queries serving different purposes: GET_PROGRAM_DETAILS fetches comprehensive program information while GET_PROGRAM_ADMIN_DETAILS fetches only admin-related details. These queries cannot be removed or merged as they serve different use cases in the application.

Applied to files:

  • frontend/src/server/queries/programsQueries.ts
  • frontend/src/server/queries/moduleQueries.ts
📚 Learning: 2025-08-31T13:47:15.833Z
Learnt from: rudransh-shrivastava
PR: OWASP/Nest#2155
File: frontend/src/server/queries/programsQueries.ts:81-81
Timestamp: 2025-08-31T13:47:15.833Z
Learning: In frontend/src/server/queries/programsQueries.ts, GET_PROGRAM_DETAILS is actively used in frontend/src/app/my/mentorship/programs/[programKey]/edit/page.tsx for program editing functionality and cannot be removed. It serves a different purpose than GET_PROGRAM_ADMIN_DETAILS, providing comprehensive program information needed for editing.

Applied to files:

  • frontend/src/server/queries/programsQueries.ts
  • frontend/src/server/queries/moduleQueries.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: CodeQL (javascript-typescript)
🔇 Additional comments (15)
frontend/src/server/queries/committeeQueries.ts (1)

6-6: IDs added for Apollo normalization — LGTM.

Adding id to committee, topContributors, and metadata should resolve cache identity issues.

If you previously had custom typePolicies for these types, confirm they still key by id (or remove overrides) to avoid duplicate entities.

Also applies to: 21-21, 32-32

frontend/src/server/queries/apiKeyQueries.ts (1)

7-7: No custom cache policy found; Apollo Client defaults to using id for normalization. The codebase contains no typePolicies or keyFields for ApiKey, so InMemoryCache will automatically generate identifiers as ApiKey:<id> by default (unpkg.com).

frontend/src/server/queries/projectsHealthDashboardQueries.ts (1)

28-28: Health metric IDs added — verify they identify snapshots, not projects.

For healthMetricsLatest and healthMetricsList, ensure id refers to the metric entry/snapshot. If it’s the project id, Apollo will collapse distinct timepoints into one cache entry.

If unsure, quickly check server schema/resolvers for the ProjectHealthMetric type to confirm id uniqueness per snapshot.

Also applies to: 43-46, 62-62

frontend/src/server/queries/authQueries.ts (3)

6-6: LGTM: Adding id to logoutUser payload improves Apollo normalization.


20-21: LGTM: Adding user.id is correct for cache identity.


6-6: Verify backend schema exposes id for logoutUser and auth user

Frontend queries already request id (frontend/src/server/queries/authQueries.ts — logoutUser { id, ... } and the auth response user { id, ... }); repository search did not locate server-side SDL/resolver definitions that explicitly declare id on the logout response or the auth user type. Confirm backend GraphQL types/resolvers return id for logoutUser and githubAuth.user to avoid runtime query errors.

frontend/src/server/queries/projectQueries.ts (1)

6-6: LGTM: Consistent id additions across project, metrics, nested authors, repositories, milestones, PRs, and topContributors.
These will stabilize Apollo cache keys without altering inputs.

Also applies to: 17-17, 33-33, 47-47, 60-60, 82-82, 97-97, 110-110, 121-121, 129-129, 153-153

frontend/src/server/queries/chapterQueries.ts (1)

6-6: LGTM: Added ids for chapter and topContributors selections.
Matches the PR’s objective and should aid cache identity.

Also applies to: 22-22, 33-33

frontend/src/server/queries/moduleQueries.ts (1)

40-44: LGTM: Adding id to mentors/admins selections is consistent and beneficial.

Also applies to: 54-58, 73-77

frontend/src/server/queries/programsQueries.ts (1)

54-58: LGTM: ids added to admins and mentors selections across queries.
This aligns with the cache-fix objective without changing variables.

Also applies to: 77-81, 92-96, 108-112

frontend/src/server/queries/snapshotQueries.ts (1)

6-6: LGTM on adding ids (improves Apollo normalization).

Adding id to snapshot, newReleases, newProjects (plus topContributors), newChapters (plus topContributors), and snapshots list is correct and low-risk.

Also applies to: 12-17, 19-35, 37-58, 75-80

frontend/src/server/queries/organizationQueries.ts (2)

6-26: LGTM on id additions across organization data.

Adding id to organization, lists (issues, PRs, releases, milestones), authors, repositories, and organization within repositories aligns with Apollo cache best practices.

Also applies to: 28-32, 34-46, 48-61, 63-77, 79-91, 93-105


6-6: No typePolicies or keyFields overrides detected
Verified both InMemoryCache instances in frontend/src/server/apolloClient.ts and frontend/src/utils/helpers/apolloClient.ts have no custom typePolicies or keyFields, so default __typename + id normalization applies.

frontend/src/server/queries/userQueries.ts (2)

6-10: LGTM on id additions for user, activity lists, and repositories.

This should resolve Apollo warnings and improves cache normalization. Remember to regenerate GraphQL types/artifacts if you use codegen.

Also applies to: 17-23, 25-33, 35-41, 43-51, 53-66, 68-85, 91-95


3-12: Verify GraphQL operation name uniqueness: The automation scripts weren’t reliably extracting names—manually ensure all query, mutation, and subscription operation names in frontend/src/server/queries/*.ts are unique.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
backend/tests/apps/github/api/internal/queries/repository_contributor_test.py (2)

20-21: Add assertions to verify id is propagated to result nodes.

Mock data now includes id, but tests don’t assert it’s carried through by the resolver. Add quick checks to prevent regressions.

Python snippets to add:

# In test_top_contributors_basic, after other assertions:
assert result[0].id == "1"
assert isinstance(result[0].id, str)
assert result[1].id == "2"

# In test_top_contributors_with_limit, after asserting login:
assert result[0].id == "1"

Also applies to: 29-30


129-131: Also assert id on the constructed node.

This test validates field mapping; include id to fully cover the new field.

# After node = result[0] and existing field asserts:
assert node.id == "3"
assert isinstance(node.id, str)
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4854614 and 5508c13.

📒 Files selected for processing (2)
  • backend/tests/apps/github/api/internal/queries/repository_contributor_test.py (3 hunks)
  • backend/tests/apps/github/models/repository_contributor_test.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • backend/tests/apps/github/models/repository_contributor_test.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: CodeQL (javascript-typescript)

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

Hi @Piyushrathoree ! Thanks for working on this.
once started the server I noticed there were some issues on compiling the home page. Apparently, one node still missed an id on the backend.
So I fixed that (and tests) and pushed the update to your PR.

The rest works great!

Thanks!

@kasya kasya enabled auto-merge September 1, 2025 00:07
@Piyushrathoree
Copy link
Collaborator Author

Hi @Piyushrathoree ! Thanks for working on this. once started the server I noticed there were some issues on compiling the home page. Apparently, one node still missed an id on the backend. So I fixed that (and tests) and pushed the update to your PR.

The rest works great!

Thanks!

@kasya can you share some more details because I'm not seeing any issue

@Piyushrathoree Piyushrathoree requested a review from kasya September 1, 2025 16:39
@arkid15r
Copy link
Collaborator

arkid15r commented Sep 1, 2025

@kasya can you share some more details because I'm not seeing any issue

Those were fixed in 5508c13

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 1, 2025

@kasya kasya added this pull request to the merge queue Sep 1, 2025
Merged via the queue into OWASP:main with commit 217ef1a Sep 1, 2025
25 checks passed
@Piyushrathoree Piyushrathoree deleted the feature/adding-id-in-frontend-queries branch September 2, 2025 04:36
Dishant1804 pushed a commit to Dishant1804/Nest that referenced this pull request Sep 6, 2025
* added ids to frontend graphql queries

* Add top contributors ID

* Fix tests

---------

Co-authored-by: Kate <kate@kgthreads.com>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add id to Frontend GraphQL Queries

3 participants