Skip to content
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

Feat/user sitemap list #1887

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open

Feat/user sitemap list #1887

wants to merge 3 commits into from

Conversation

kkatusic
Copy link
Collaborator

@kkatusic kkatusic commented Dec 5, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new UserPublicData class for streamlined user data representation in GraphQL.
    • Added AllUsersPublicData type and allUsersBasicData query for retrieving paginated user data.
    • Implemented a new GraphQL query allUsersBasicDataQuery for fetching basic user data with pagination support.
  • Bug Fixes

    • None
  • Documentation

    • Updated GraphQL schema to include new user data types.

@kkatusic kkatusic requested a review from CarlosQ96 December 5, 2024 12:31
@kkatusic kkatusic self-assigned this Dec 5, 2024
Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Walkthrough

The changes introduce a new class, UserPublicData, in the src/entities/user.ts file for GraphQL representation, containing optional fields for user information. Additionally, a new GraphQL object type, AllUsersPublicData, and a query method, allUsersBasicData, are added to the UserResolver class in src/resolvers/userResolver.ts. This method allows clients to retrieve a paginated list of users, utilizing TypeORM to fetch the data while maintaining existing control flow and logic. A corresponding test suite for the new query is also included.

Changes

File Path Change Summary
src/entities/user.ts - Added new class UserPublicData with fields: firstName, lastName, name, walletAddress (all optional, type String).
src/resolvers/userResolver.ts - Added new ObjectType AllUsersPublicData with fields: users (array of UserPublicData), totalCount (number).
- Added new method async allUsersBasicData(limit: number = 50, skip: number = 0): Promise<AllUsersPublicData> to retrieve paginated user data.
- Updated import statement to include UserPublicData.
src/resolvers/userResolver.test.ts - Added new test suite for allUsersBasicData functionality, validating query behavior with limits and skips, and ensuring sensitive fields are excluded.
test/graphqlQueries.ts - Added new query allUsersBasicDataQuery to fetch basic data for all users with pagination support.

Possibly related PRs

Suggested labels

Code Review

Suggested reviewers

  • CarlosQ96

Poem

In the world of code, a new tale unfolds,
With UserPublicData, a story told.
Users gather round, their data in sight,
Paginated queries, oh what a delight!
With fields so bright, they shine like the moon,
In the land of GraphQL, we'll sing a new tune! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • 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: 3

🧹 Outside diff range and nitpick comments (2)
src/entities/user.ts (1)

267-280: LGTM! Consider adding JSDoc documentation.

The UserPublicData class is well-structured and appropriately exposes only non-sensitive user information. The fields are correctly marked as optional and nullable.

Consider adding JSDoc documentation to describe the purpose of this class and its relationship with the main User entity:

+/**
+ * Represents the publicly accessible user data for the sitemap.
+ * This is a subset of the main User entity containing only non-sensitive information.
+ */
@ObjectType()
export class UserPublicData extends BaseEntity {
src/resolvers/userResolver.ts (1)

47-54: Consider a more specific class name.

The class structure is good for pagination, but the name could be more specific about its purpose.

Consider renaming to better reflect its use in the sitemap:

-class AllUsersPublicData {
+class UserSitemapPaginatedResponse {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 795e035 and e5605eb.

📒 Files selected for processing (2)
  • src/entities/user.ts (1 hunks)
  • src/resolvers/userResolver.ts (3 hunks)
🔇 Additional comments (1)
src/resolvers/userResolver.ts (1)

436-459: Verify performance impact on production dataset.

The query fetches user data for the sitemap. Let's verify the potential impact on performance.

✅ Verification successful

Let me try a different approach to gather information about the database schema and similar query patterns.


Based on the gathered information, I can now provide a final response:

Query implementation follows established patterns and includes proper pagination

The implementation follows the same pagination pattern used throughout the codebase, particularly in projectRepository.ts and instantBoostingRepository.ts. The query:

  • Selects only necessary fields (firstName, lastName, name, walletAddress)
  • Uses standard TypeORM pagination with skip() and take()
  • Has a reasonable default limit of 50 records
  • Matches similar implementations in other repositories that handle user data
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the total number of users to understand the scale
echo "Checking total number of users..."
rg -A 1 "SELECT.*FROM.*user.*COUNT" --glob "*.sql"

# Check if there are any existing indexes that could be used
echo "Checking existing indexes..."
rg -A 5 "CREATE.*INDEX.*user" --glob "*.sql"

# Look for similar pagination patterns in the codebase
echo "Checking similar pagination patterns..."
ast-grep --pattern 'createQueryBuilder($x)
  .skip($_)
  .take($_)'

Length of output: 700


Script:

#!/bin/bash
# Check for database migration files
echo "Checking for migration files..."
fd -e ts -e js migration

# Look for similar queries in resolver files
echo "Checking resolver patterns..."
rg -A 5 "createQueryBuilder\('user'\)" --type ts

# Check if there are any performance-related configurations
echo "Checking for TypeORM configurations..."
fd -e ts -e js "ormconfig"

# Look for other paginated queries
echo "Looking for other paginated queries..."
rg "take\(.*limit" --type ts

Length of output: 3639

src/resolvers/userResolver.ts Show resolved Hide resolved
src/resolvers/userResolver.ts Show resolved Hide resolved
src/resolvers/userResolver.ts Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (1)
src/resolvers/userResolver.test.ts (1)

1175-1252: Consider adding more test cases for edge cases and error scenarios.

While the current test suite covers the basic functionality well, consider adding the following test cases to improve coverage:

  • Invalid inputs (negative skip/limit)
  • Empty database scenario
  • Result ordering verification
  • Maximum limit validation
  • Invalid parameter types
 function allUsersBasicData() {
   describe('allUsersBasicData Test Cases', () => {
+    it('should handle empty database gracefully', async () => {
+      // Clear users table first
+      const result = await axios.post(graphqlUrl, {
+        query: allUsersBasicDataQuery,
+      });
+      const { users, totalCount } = result.data.data.allUsersBasicData;
+      assert.isArray(users);
+      assert.equal(users.length, 0);
+      assert.equal(totalCount, 0);
+    });
+
+    it('should validate negative skip/limit parameters', async () => {
+      const result = await axios.post(graphqlUrl, {
+        query: allUsersBasicDataQuery,
+        variables: { skip: -1, limit: -5 },
+      });
+      assert.exists(result.data.errors);
+    });
+
     // Existing test cases...
   });
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e5605eb and fd8ea0e.

📒 Files selected for processing (2)
  • src/resolvers/userResolver.test.ts (3 hunks)
  • test/graphqlQueries.ts (1 hunks)
🔇 Additional comments (2)
src/resolvers/userResolver.test.ts (1)

20-20: LGTM!

The import and test suite registration follow the established pattern in the codebase.

Also applies to: 38-38

test/graphqlQueries.ts (1)

2613-2626: LGTM! Well-structured GraphQL query.

The query is well-designed with:

  • Proper pagination support
  • Only non-sensitive user fields
  • Clear field naming

Copy link
Collaborator

@CarlosQ96 CarlosQ96 left a comment

Choose a reason for hiding this comment

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

LGTM! thanks kechy

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