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

chore(rethinkdb): TeamMember: Phase 3 #10003

Merged
merged 21 commits into from
Jul 24, 2024
Merged

Conversation

mattkrick
Copy link
Member

@mattkrick mattkrick commented Jul 19, 2024

Description

Moves reads to PG

Summary by CodeRabbit

  • New Features

    • Enhanced clarity of type references related to OrganizationUser and TeamMember for better semantic understanding.
  • Bug Fixes

    • Removed the RepoIntegrationQueryPayload type from the GraphQL schema, which may affect existing queries or mutations related to integrations.
    • Updated data loading logic to ensure non-null values for team members and users, improving data reliability.
  • Chores

    • Refined naming conventions in type references for improved context within the application.

Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
@mattkrick mattkrick changed the title Chore/team member phase3 chore(rethinkdb): TeamMember: Phase 3 Jul 19, 2024
Copy link
Contributor

coderabbitai bot commented Jul 19, 2024

Walkthrough

The changes primarily refine type definitions and references for entities related to TeamMember and OrganizationUser, transitioning from RethinkDB to PostgreSQL. This includes clarifying type naming conventions and removing unused GraphQL types. The updates improve the maintainability and robustness of the codebase without altering core functionality, ensuring a smoother transition for future development efforts.

Changes

Files Change Summary
codegen.json Updated type references for OrganizationUser (now OrganizationUserDB) and simplified TeamMember, enhancing clarity and context.
packages/server/graphql/public/typeDefs/_legacy.graphql Removed RepoIntegrationQueryPayload, impacting integration-related queries and necessitating updates in client-side code.
packages/server/graphql/public/types/AddTeamMemberIntegrationAuthSuccess.ts, .../RemoveTeamMemberIntegrationAuthSuccess.ts Modified data loading logic to use loadNonNull, ensuring data retrieval for team members is robust and non-null.
packages/server/graphql/mutations/removeTeamMember.ts, .../archiveTeam.ts Enhanced data retrieval methods to ensure non-null values for teamMember, improving robustness and error handling.
packages/server/graphql/public/types/TeamMember.ts, .../index.d.ts Updated import paths and type definitions for a PostgreSQL-centric model, reflecting the new structure and enhancing data integrity.
packages/server/safeMutations/acceptTeamInvitation.ts, .../authorization.ts Removed functions related to team member management, indicating a refactor of team invitation handling and authorization logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GraphQL
    participant PostgreSQL
    participant DataLoader

    User->>GraphQL: Request to join team
    GraphQL->>DataLoader: Load team member information
    DataLoader->>PostgreSQL: Fetch member details
    PostgreSQL-->>DataLoader: Return member details
    DataLoader-->>GraphQL: Provide member data
    GraphQL-->>User: Confirm membership
Loading
sequenceDiagram
    participant User
    participant GraphQL
    participant PostgreSQL

    User->>GraphQL: Archive team request
    GraphQL->>PostgreSQL: Verify team lead status
    PostgreSQL-->>GraphQL: Return lead status
    GraphQL-->>User: Confirm team archived
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 89154f0 and 9655589.

Files selected for processing (2)
  • packages/server/graphql/public/types/AddTeamMemberIntegrationAuthSuccess.ts (1 hunks)
  • packages/server/graphql/public/types/RemoveTeamMemberIntegrationAuthSuccess.ts (1 hunks)
Additional comments not posted (5)
packages/server/graphql/public/types/RemoveTeamMemberIntegrationAuthSuccess.ts (2)

13-13: Improvement: Ensuring non-null data retrieval for team members.

The use of loadNonNull ensures that the function will throw an error if the team member is not found, preventing potential null reference errors.

However, verify that the error handling for this scenario is adequate throughout the codebase.


14-14: Improvement: Ensuring non-null data retrieval for users.

The use of loadNonNull ensures that the function will throw an error if the user is not found, preventing potential null reference errors.

However, verify that the error handling for this scenario is adequate throughout the codebase.

packages/server/graphql/public/types/AddTeamMemberIntegrationAuthSuccess.ts (3)

16-16: Improvement: Ensuring non-null data retrieval for team members.

The use of loadNonNull ensures that the function will throw an error if the team member is not found, preventing potential null reference errors.

However, verify that the error handling for this scenario is adequate throughout the codebase.


13-13: Ensure the presence of integrationAuth data.

The function uses load and asserts non-null with !. Ensure that the data guarantee is valid and handled appropriately.


14-14: Improvement: Ensuring non-null data retrieval for users.

The use of loadNonNull ensures that the function will throw an error if the user is not found, preventing potential null reference errors.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR will be delayed and might be rejected due to its size.

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: 1

Outside diff range, codebase verification and nitpick comments (5)
packages/server/safeMutations/acceptTeamInvitation.ts (1)

Potential Issue with Team Membership Management

The removal of the insertNewTeamMember function from acceptTeamInvitation might have led to improper handling of team membership. There is no clear indication that team membership is being managed correctly within the acceptTeamInvitation function or through other mechanisms.

  • File: packages/server/safeMutations/acceptTeamInvitation.ts

Please review and ensure that team membership is correctly managed after the removal of insertNewTeamMember.

Analysis chain

Line range hint 1-124:
Verify the impact of removing insertNewTeamMember.

The removal of insertNewTeamMember changes the control flow. Ensure that team membership is correctly managed elsewhere in the code.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of removing `insertNewTeamMember`.

# Test: Search for the function usage. Expect: Correct management of team membership.
rg --type typescript -A 5 $'insertNewTeamMember'

Length of output: 82


Script:

#!/bin/bash
# Description: Verify the impact of removing `insertNewTeamMember`.

# Test: Search for the function usage. Expect: Correct management of team membership.
rg --type ts -A 5 $'insertNewTeamMember'

Length of output: 741


Script:

#!/bin/bash
# Description: Verify how team membership is managed in `acceptTeamInvitation.ts` after removing `insertNewTeamMember`.

# Test: Search for team membership management in `acceptTeamInvitation.ts`.
rg --type ts -A 10 'acceptTeamInvitation' packages/server/safeMutations/acceptTeamInvitation.ts

Length of output: 467


Script:

#!/bin/bash
# Description: Verify how team membership is managed in `acceptTeamInvitation` after removing `insertNewTeamMember`.

# Test: Search for all references to `acceptTeamInvitation` across the codebase.
rg --type ts 'acceptTeamInvitation'

Length of output: 8008

packages/server/graphql/mutations/joinMeeting.ts (1)

85-85: Ensure consistent usage of loadNonNull for teamMembers.

The following instances still use load instead of loadNonNull:

  • packages/server/graphql/types/AddAtlassianAuthPayload.ts
  • packages/server/graphql/types/AddTeamMemberIntegrationAuthPayload.ts
  • packages/server/graphql/types/MeetingMember.ts
  • packages/server/graphql/types/ToggleTeamDrawerPayload.ts
  • packages/server/graphql/types/User.ts
  • packages/server/graphql/types/UpdateIntegrationProviderPayload.ts
  • packages/server/graphql/types/SetDefaultSlackChannelPayload.ts
  • packages/server/graphql/types/RemoveTeamMemberIntegrationAuthPayload.ts
  • packages/server/graphql/types/RemoveAtlassianAuthPayload.ts
  • packages/server/graphql/types/RemoveGitHubAuthPayload.ts
  • packages/server/graphql/types/RemoveIntegrationProviderPayload.ts
  • packages/server/graphql/types/AddGitHubAuthPayload.ts
  • packages/server/graphql/resolvers.ts
  • packages/server/graphql/queries/massInvitation.ts
  • packages/server/graphql/public/types/MeetingTemplate.ts
  • packages/server/graphql/mutations/archiveTeam.ts
  • packages/server/graphql/public/types/UpdateUserProfilePayload.ts
  • packages/server/graphql/public/types/DomainJoinRequest.ts
  • packages/server/graphql/public/rules/isViewerOnTeam.ts
  • packages/server/graphql/mutations/createTask.ts

Please review and update these instances where necessary to ensure the use of loadNonNull for teamMembers.

Analysis chain

LGTM! Ensure consistent usage of loadNonNull.

The change to use loadNonNull instead of load enhances data integrity by ensuring teamMember is never null.

However, ensure that all similar function calls are updated to use loadNonNull where necessary.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `load` are updated to `loadNonNull` where necessary.

# Test: Search for the function usage. Expect: Only occurrences of `loadNonNull` for `teamMembers`.
rg --type js --type ts -A 5 $'.get(\'teamMembers\').load'

Length of output: 62


Script:

#!/bin/bash
# Description: Verify all function calls to `load` are updated to `loadNonNull` where necessary.

# Test: Search for the function usage. Expect: Only occurrences of `loadNonNull` for `teamMembers`.
rg --type js --type ts -A 5 "\.get\('teamMembers'\)\.load"

Length of output: 16836

packages/server/graphql/mutations/startSprintPoker.ts (1)

166-166: Inconsistent usage of loadNonNull for teamMembers detected.

The following files still use .get('teamMembers').load instead of loadNonNull:

  • packages/server/graphql/resolvers.ts
    • Line 1: return teamMemberId ? dataLoader.get('teamMembers').load(teamMemberId) : teamMember
    • Line 2: ? dataLoader.get('teamMembers').loadMany(teamMemberIds) : teamMembers
  • packages/server/graphql/types/AddAtlassianAuthPayload.ts
    • Line 1: return dataLoader.get('teamMembers').load(teamMemberId)
  • packages/server/graphql/types/AddTeamMemberIntegrationAuthPayload.ts
    • Line 1: return dataLoader.get('teamMembers').load(teamMemberId)
  • packages/server/graphql/types/RemoveIntegrationProviderPayload.ts
    • Line 1: return dataLoader.get('teamMembers').load(teamMemberId)
  • packages/server/graphql/mutations/archiveTeam.ts
    • Line 1: dataLoader.get('teamMembers').load(TeamMemberId.join(teamId, viewerId))
  • packages/server/graphql/types/User.ts
    • Line 1: return dataLoader.get('teamMembers').load(teamMemberId)
  • packages/server/graphql/types/ToggleTeamDrawerPayload.ts
    • Line 1: return dataLoader.get('teamMembers').load(teamMemberId)
  • packages/server/graphql/types/SetDefaultSlackChannelPayload.ts
    • Line 1: return dataLoader.get('teamMembers').load(teamMemberId)
  • packages/server/graphql/types/UpdateIntegrationProviderPayload.ts
    • Line 1: return dataLoader.get('teamMembers').load(teamMemberId)
  • packages/server/graphql/mutations/createTask.ts
    • Line 1: const teamMember = await dataLoader.get('teamMembers').load(teamMemberId)
  • packages/server/graphql/queries/massInvitation.ts
    • Line 1: dataLoader.get('teamMembers').load(teamMemberId)
  • packages/server/graphql/public/types/MeetingTemplate.ts
    • Line 1: const teamMember = await dataLoader.get('teamMembers').load(teamMemberId)
  • packages/server/graphql/public/rules/isViewerOnTeam.ts
    • Line 1: const teamMember = await dataLoader.get('teamMembers').load(teamMemberId)

Please update these instances to use loadNonNull where appropriate to ensure data integrity and prevent potential null-related runtime errors.

Analysis chain

LGTM! Ensure consistent usage of loadNonNull.

The change to use loadNonNull instead of load enhances data integrity by ensuring teamMember is never null.

However, ensure that all similar function calls are updated to use loadNonNull where necessary.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `load` are updated to `loadNonNull` where necessary.

# Test: Search for the function usage. Expect: Only occurrences of `loadNonNull` for `teamMembers`.
rg --type js --type ts -A 5 $'.get(\'teamMembers\').load'

Length of output: 62


Script:

#!/bin/bash
# Description: Verify all function calls to `load` and `loadNonNull` for `teamMembers`.

# Test: Search for the function usage. Expect: Occurrences of `load` and `loadNonNull` for `teamMembers`.
rg --type js --type ts -A 5 $'.get(\'teamMembers\').load'
rg --type js --type ts -A 5 $'.get(\'teamMembers\').loadNonNull'

Length of output: 132


Script:

#!/bin/bash
# Description: Verify all function calls to `load` and `loadNonNull` for `teamMembers`.

# Test: Search for the function usage. Expect: Occurrences of `load` and `loadNonNull` for `teamMembers`.
rg --type js --type ts -A 5 '\.get\("teamMembers"\)\.load'
rg --type js --type ts -A 5 '\.get\("teamMembers"\)\.loadNonNull'

Length of output: 128


Script:

#!/bin/bash
# Description: Verify all function calls to `load` and `loadNonNull` for `teamMembers`.

# Test: Search for the function usage. Expect: Occurrences of `load` and `loadNonNull` for `teamMembers`.
rg --type js --type ts -A 5 '\.get\(["'\'']teamMembers["'\'']\)\.load'
rg --type js --type ts -A 5 '\.get\(["'\'']teamMembers["'\'']\)\.loadNonNull'

Length of output: 22394

packages/server/graphql/private/typeDefs/_legacy.graphql (1)

Removal of RepoIntegrationQueryPayload type definition impacts other files.

The RepoIntegrationQueryPayload type definition has been removed in packages/server/graphql/private/typeDefs/_legacy.graphql. However, this type is still referenced in the following files:

  • packages/server/graphql/types/RepoIntegrationQueryPayload.ts
  • packages/server/graphql/public/typeDefs/RepoIntegrationQueryPayload.graphql
  • packages/server/graphql/public/typeDefs/TeamMember.graphql
  • packages/server/graphql/public/typeDefs/_legacy.graphql

Ensure that all references to RepoIntegrationQueryPayload are updated or removed to prevent errors in the GraphQL API.

Analysis chain

Line range hint 1-1:
Removal of RepoIntegrationQueryPayload type definition.

The RepoIntegrationQueryPayload type definition has been removed. This type previously included fields for error, hasMore, and items. Ensure that any queries or mutations that relied on this structure are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the removal of `RepoIntegrationQueryPayload` type definition.

# Test: Search for the usage of `RepoIntegrationQueryPayload`. Expect: No occurrences.
rg --type graphql -A 5 $'RepoIntegrationQueryPayload'

Length of output: 84


Script:

#!/bin/bash
# Description: Verify the removal of `RepoIntegrationQueryPayload` type definition.

# Test: Search for the usage of `RepoIntegrationQueryPayload` across all files.
rg -A 5 'RepoIntegrationQueryPayload'

Length of output: 2874

packages/server/graphql/public/typeDefs/_legacy.graphql (1)

References to RepoIntegrationQueryPayload still exist in the codebase.

The RepoIntegrationQueryPayload type definition has been removed from packages/server/graphql/public/typeDefs/_legacy.graphql, but references to it still exist in the following files:

  • packages/server/graphql/public/typeDefs/TeamMember.graphql: Lines containing RepoIntegrationQueryPayload!
  • packages/server/graphql/public/typeDefs/_legacy.graphql: Line containing repoIntegrations: RepoIntegrationQueryPayload!
  • packages/server/graphql/public/typeDefs/RepoIntegrationQueryPayload.graphql: Line defining type RepoIntegrationQueryPayload
  • packages/server/graphql/types/RepoIntegrationQueryPayload.ts: Lines containing const RepoIntegrationQueryPayload, name: 'RepoIntegrationQueryPayload', and export default RepoIntegrationQueryPayload

Please update or remove these references to ensure consistency and prevent potential issues.

Analysis chain

Line range hint 1-1:
Verify the removal of all references to RepoIntegrationQueryPayload.

The RepoIntegrationQueryPayload type definition has been removed. Ensure that all references to this type in the codebase are also removed or updated to prevent any broken functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the removal of all references to `RepoIntegrationQueryPayload` in the codebase.

# Test: Search for references to `RepoIntegrationQueryPayload`. Expect: No occurrences found.
rg --type graphql --type js --type ts 'RepoIntegrationQueryPayload'

Length of output: 99


Script:

#!/bin/bash
# Description: Verify the removal of all references to `RepoIntegrationQueryPayload` in the codebase.

# Test: Search for references to `RepoIntegrationQueryPayload`. Expect: No occurrences found.
rg --type gql --type js --type ts 'RepoIntegrationQueryPayload'

Length of output: 91


Script:

#!/bin/bash
# Description: Verify the removal of all references to `RepoIntegrationQueryPayload` in the codebase.

# Test: Search for references to `RepoIntegrationQueryPayload`. Expect: No occurrences found.
rg 'RepoIntegrationQueryPayload'

Length of output: 776

Comment on lines 43 to 52
try {
console.log('Adding index')
await r
.table('TeamMember')
.indexCreate('updatedAtId', (row: any) => [row('updatedAt'), row('id')])
.run()
await r.table('TeamMember').indexWait().run()
} catch {
// index already exists
}
Copy link
Contributor

@coderabbitai coderabbitai bot Jul 19, 2024

Choose a reason for hiding this comment

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

Remove the redundant try-catch block.

Avoid catching errors just to log and rethrow them. Let the errors propagate naturally to be handled by the calling function or global error handler.

-  try {
-    console.log('Adding index')
-    await r
-      .table('TeamMember')
-      .indexCreate('updatedAtId', (row: any) => [row('updatedAt'), row('id')])
-      .run()
-    await r.table('TeamMember').indexWait().run()
-  } catch {
-    // index already exists
-  }
+  console.log('Adding index')
+  await r
+    .table('TeamMember')
+    .indexCreate('updatedAtId', (row: any) => [row('updatedAt'), row('id')])
+    .run()
+  await r.table('TeamMember').indexWait().run()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
console.log('Adding index')
await r
.table('TeamMember')
.indexCreate('updatedAtId', (row: any) => [row('updatedAt'), row('id')])
.run()
await r.table('TeamMember').indexWait().run()
} catch {
// index already exists
}
console.log('Adding index')
await r
.table('TeamMember')
.indexCreate('updatedAtId', (row: any) => [row('updatedAt'), row('id')])
.run()
await r.table('TeamMember').indexWait().run()

Copy link
Contributor

Choose a reason for hiding this comment

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

You did not read the catch block completely, it's not rethrowing the exception but we're ignoring it. There is even a comment explaining why.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Dschoordsch, thank you for pointing that out. I see that the catch block is not rethrowing the exception but is instead handling a specific case where the index might already exist. The comment within the catch block provides important context for this decision. I agree that it should be retained to avoid unnecessary errors during index creation.

No changes are needed here. Thank you for the clarification!


Learnings added
Learnt from: Dschoordsch
PR: ParabolInc/parabol#10003
File: packages/server/postgres/migrations/1721356124871_TeamMember-phase2.ts:43-52
Timestamp: 2024-07-22T08:24:09.222Z
Learning: When handling database operations, a try-catch block can be used to handle specific cases (e.g., index already exists) without rethrowing the exception. Comments within the catch block are important for providing context and should be considered during reviews.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


Learnings used
Learnt from: Dschoordsch
PR: ParabolInc/parabol#9979
File: packages/server/postgres/migrations/1720730818119_TeamMember-phase1.ts:54-54
Timestamp: 2024-07-18T08:33:51.211Z
Learning: When handling database disconnections, avoid catching errors just to log and rethrow them. Let the errors propagate naturally to be handled by the calling function or global error handler.

@github-actions github-actions bot added size/l and removed size/xl labels Jul 23, 2024
Signed-off-by: Matt Krick <matt.krick@gmail.com>
@mattkrick mattkrick merged commit 73a5881 into master Jul 24, 2024
7 checks passed
@mattkrick mattkrick deleted the chore/teamMember-phase3 branch July 24, 2024 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants