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

Dataloader can now resolve to null for nullable fields #4773

Merged
merged 3 commits into from
Dec 11, 2024

Conversation

hero101
Copy link
Collaborator

@hero101 hero101 commented Dec 11, 2024

Added option for the dataloader to be able to resolve fields to null if they are nullable

Summary by CodeRabbit

  • New Features

    • Enhanced error handling in data loaders, allowing for more flexible responses, including returning null or exceptions.
    • Updated resolver methods to support nullable return types, improving error handling in the GraphQL API.
  • Bug Fixes

    • Adjusted property signatures in notification classes to allow for optional or mandatory fields as needed.
  • Documentation

    • Updated method signatures and property declarations to reflect changes in functionality and error handling.

Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

The changes in this pull request involve modifications to several classes and interfaces related to data loading within the application. Key updates include altering method signatures to allow for more flexible return types, enabling loaders to return null or EntityNotFoundException in addition to their usual types. Additionally, new optional parameters for configuration have been introduced in the create methods of various loader creators. The modifications extend to the resolver methods, which have been updated to handle nullable responses more effectively.

Changes

File Change Summary
src/core/dataloader/creators/base/data.loader.creator.ts Updated create method signature to return `ILoader<TReturn
src/core/dataloader/creators/base/index.ts Added export statement for data.loader.creator.base.options.
src/core/dataloader/creators/loader.creators/in-app-notification/callout.loader.creator.ts Updated create method to accept DataLoaderCreatorBaseOptions and modified return type to include null and EntityNotFoundException.
src/core/dataloader/creators/loader.creators/in-app-notification/community.type.loader.creator.ts Updated create method to accept DataLoaderCreatorBaseOptions and modified return type to include null and EntityNotFoundException.
src/core/dataloader/creators/loader.creators/in-app-notification/contributor.loader.creator.ts Updated create method to accept DataLoaderCreatorBaseOptions and modified return type to include null and EntityNotFoundException.
src/core/dataloader/creators/loader.creators/in-app-notification/space.loader.creator.ts Updated create method to accept DataLoaderCreatorBaseOptions and modified return type to include null and EntityNotFoundException.
src/core/dataloader/utils/createTypedBatchLoader.ts Updated createBatchLoader signature to accept options and modified return type to include null and EntityNotFoundException.
src/domain/in-app-notification-reader/dto/in.app.notification.callout.published.ts Changed callout and space properties from mandatory to optional.
src/domain/in-app-notification-reader/dto/in.app.notification.community.new.member.ts Changed contributorType property from optional to mandatory.
src/domain/in-app-notification-reader/dto/in.app.notification.user.mentioned.ts Changed contributorType, comment, and commentUrl properties from optional to mandatory.
src/domain/in-app-notification-reader/field-resolvers/in.app.notification.callout.published.resolver.fields.ts Updated callout and space resolver methods to allow null responses and modified @Loader decorators accordingly.
src/domain/in-app-notification-reader/field-resolvers/in.app.notification.community.new.member.resolver.fields.ts Updated actor and space resolver methods to allow null responses and modified @Loader decorators accordingly.
src/core/dataloader/utils/createTypedRelationLoader.ts Updated createTypedRelationDataLoader return type to include null and EntityNotFoundException.
src/core/dataloader/utils/createTypedSimpleLoader.ts Updated createTypedSimpleDataLoader return type to include null and EntityNotFoundException.

Possibly related PRs

  • remove innovation flow from template #4746: The changes in this PR involve modifications to the create method's return type to include null and EntityNotFoundException, which aligns with the main PR's updates to enhance error handling capabilities in the DataLoaderCreator interface.

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

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.

@hero101 hero101 requested a review from Comoque1 December 11, 2024 14:33
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 and nitpick comments (6)
src/domain/in-app-notification-reader/dto/in.app.notification.callout.published.ts (1)

18-19: LGTM! Properties correctly marked as optional for GraphQL resolution.

The change to optional properties (callout? and space?) aligns well with the dataloader's new ability to resolve to null, ensuring type-safety throughout the resolution chain.

Consider documenting these nullable fields in your GraphQL schema documentation to help API consumers understand when and why these fields might be null. This is especially important for breaking changes where previously non-null fields become nullable.

src/core/dataloader/creators/loader.creators/in-app-notification/space.loader.creator.ts (1)

18-25: Consider documenting the null resolution pattern

Since this is a significant change in how loaders handle missing entities, consider:

  1. Adding documentation about when to use resolveToNull vs letting it throw EntityNotFoundException
  2. Updating GraphQL schema documentation to reflect which fields can resolve to null
  3. Adding integration tests to verify the behavior with nullable fields
src/domain/in-app-notification-reader/field-resolvers/in.app.notification.community.new.member.resolver.fields.ts (1)

24-24: Address the TODO comment about renaming

While the nullable field implementation looks good, there's a TODO comment about renaming the actor method. Consider addressing this naming concern before merging.

Would you like me to help analyze potential alternative names for this method?

Also applies to: 30-31

src/core/dataloader/creators/loader.creators/in-app-notification/community.type.loader.creator.ts (1)

Line range hint 28-48: Consider optimizing the query performance

The batch loading query joins multiple tables and performs type checking. While the implementation is correct, consider monitoring its performance with large datasets.

Would you like me to suggest potential optimization strategies or help set up performance monitoring?

src/core/dataloader/creators/loader.creators/in-app-notification/contributor.loader.creator.ts (1)

26-30: Consider adding debug options conditionally

The debugging options (name, loadedTypeName) are always included, which is good for development but might impact production performance.

Consider conditionally including debug options based on environment:

    return createBatchLoader(this.contributorsInBatch, {
-     name: this.constructor.name,
-     loadedTypeName: 'Contributor',
+     ...(process.env.NODE_ENV !== 'production' && {
+       name: this.constructor.name,
+       loadedTypeName: 'Contributor',
+     }),
      resolveToNull: options?.resolveToNull,
    });
src/core/dataloader/utils/createTypedBatchLoader.ts (1)

37-46: Consider enhancing error context

While the error handling is good, we could provide more detailed context for debugging.

Consider enhancing the error context:

    return resolveToNull
      ? null
      : new EntityNotFoundException(
-         `Could not find ${loadedTypeName} for the given key`,
+         `Could not find ${loadedTypeName} with ID ${key}`,
          LogContext.DATA_LOADER,
-         { id: key }
+         { id: key, loader: name }
        );
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f67bd11 and 68f3332.

📒 Files selected for processing (12)
  • src/core/dataloader/creators/base/data.loader.creator.ts (1 hunks)
  • src/core/dataloader/creators/base/index.ts (1 hunks)
  • src/core/dataloader/creators/loader.creators/in-app-notification/callout.loader.creator.ts (1 hunks)
  • src/core/dataloader/creators/loader.creators/in-app-notification/community.type.loader.creator.ts (2 hunks)
  • src/core/dataloader/creators/loader.creators/in-app-notification/contributor.loader.creator.ts (1 hunks)
  • src/core/dataloader/creators/loader.creators/in-app-notification/space.loader.creator.ts (1 hunks)
  • src/core/dataloader/utils/createTypedBatchLoader.ts (2 hunks)
  • src/domain/in-app-notification-reader/dto/in.app.notification.callout.published.ts (1 hunks)
  • src/domain/in-app-notification-reader/dto/in.app.notification.community.new.member.ts (1 hunks)
  • src/domain/in-app-notification-reader/dto/in.app.notification.user.mentioned.ts (1 hunks)
  • src/domain/in-app-notification-reader/field-resolvers/in.app.notification.callout.published.resolver.fields.ts (1 hunks)
  • src/domain/in-app-notification-reader/field-resolvers/in.app.notification.community.new.member.resolver.fields.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/core/dataloader/creators/base/index.ts
🧰 Additional context used
📓 Path-based instructions (11)
src/core/dataloader/creators/base/data.loader.creator.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
src/domain/in-app-notification-reader/dto/in.app.notification.community.new.member.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
src/domain/in-app-notification-reader/dto/in.app.notification.callout.published.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
src/domain/in-app-notification-reader/dto/in.app.notification.user.mentioned.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
src/core/dataloader/utils/createTypedBatchLoader.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
src/core/dataloader/creators/loader.creators/in-app-notification/callout.loader.creator.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
src/core/dataloader/creators/loader.creators/in-app-notification/contributor.loader.creator.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
src/core/dataloader/creators/loader.creators/in-app-notification/space.loader.creator.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
src/core/dataloader/creators/loader.creators/in-app-notification/community.type.loader.creator.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
src/domain/in-app-notification-reader/field-resolvers/in.app.notification.callout.published.resolver.fields.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
src/domain/in-app-notification-reader/field-resolvers/in.app.notification.community.new.member.resolver.fields.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
🔇 Additional comments (15)
src/domain/in-app-notification-reader/dto/in.app.notification.user.mentioned.ts (1)

20-22: Verify the requirement of non-null fields.

The properties contributorType, comment, and commentUrl have been changed from optional to required. While this makes the contract more strict, we should verify that these fields are always available when creating notifications.

Let's check the notification creation flow:

✅ Verification successful

Let me gather more information about the notification payload and resolver to understand how these fields are populated.


Let me try a different approach to find the resolver and payload implementations.


Let me check the resolver implementation and the payload structure.


The non-null fields are correctly implemented and required

The change from optional to required fields is correct and intentional based on the following evidence:

  1. The resolver implementation shows that all fields are guaranteed to be populated from the payload:

    • contributorType is resolved from payload.contributorType
    • comment is resolved from payload.comment
    • commentUrl is resolved from payload.commentOrigin.url
  2. The resolver fields are explicitly decorated with nullable: false, indicating these fields should never be null in the GraphQL schema.

  3. The fields are resolved synchronously with direct property access, meaning the values are expected to be always present in the payload.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for places where InAppNotificationUserMentioned is created
ast-grep --pattern 'new InAppNotificationUserMentioned({
  $$$
})'

# Search for the payload creation to verify field availability
rg -A 5 "InAppNotificationContributorMentionedPayload"

Length of output: 1587


Script:

#!/bin/bash
# Search for the resolver implementation
ast-grep --pattern 'class $_ implements $_ {
  $$$
  resolve$_($_, $_): $_ {
    $$$
  }
}'

# Search for the payload type definition
rg -A 10 "class InAppNotificationContributorMentionedPayload"

# Search for tests to verify field population
rg -l "InAppNotificationUserMentioned.*test"

Length of output: 204


Script:

#!/bin/bash
# Search for resolver files
fd resolver

# Search for files containing InAppNotificationUserMentioned
rg -l "InAppNotificationUserMentioned"

# Search for the payload type in notifications library imports
rg -A 5 "from '@alkemio/notifications-lib'" 

Length of output: 24998


Script:

#!/bin/bash
# Check the resolver implementation
cat src/domain/in-app-notification-reader/field-resolvers/in.app.notification.user.mentioned.resolver.fields.ts

# Check the notification interface
cat src/domain/in-app-notification-reader/in.app.notification.interface.ts

Length of output: 4099

src/domain/in-app-notification-reader/dto/in.app.notification.community.new.member.ts (1)

21-21: Verify the requirement change for contributorType

The change from optional to required for contributorType seems to contradict the PR's objective of handling nullable fields. Please confirm if this field should always be present when a new community member notification is created.

src/core/dataloader/creators/loader.creators/in-app-notification/callout.loader.creator.ts (2)

4-7: LGTM! Clean import organization

The imports are well organized, separating core functionality from exceptions.

Also applies to: 11-11


17-24: LGTM! Well-implemented loader creation with null resolution support

The implementation correctly supports the new nullable field resolution:

  • Proper typing with union type ICallout | null | EntityNotFoundException
  • Clean options passing to createBatchLoader
  • Consistent naming convention for loader configuration
src/core/dataloader/creators/loader.creators/in-app-notification/space.loader.creator.ts (2)

4-7: LGTM! Consistent import structure

The imports follow the same pattern as other loader creators, maintaining codebase consistency.

Also applies to: 12-12


18-25: LGTM! Well-implemented loader creation with proper typing

The implementation:

  • Correctly implements the nullable resolution pattern
  • Maintains consistency with other loader creators
  • Properly types the return value to include null and EntityNotFoundException
src/domain/in-app-notification-reader/field-resolvers/in.app.notification.callout.published.resolver.fields.ts (2)

15-15: LGTM! Consistent handling of nullable callout field

The changes correctly implement nullable field resolution for the callout field, aligning with the PR objective. The combination of nullable: true in the field definition and resolveToNull: true in the loader ensures proper null handling.

Also applies to: 20-21


27-27: LGTM! Consistent handling of nullable space field

The changes mirror the callout field implementation, maintaining consistency in how nullable fields are handled across the resolver.

Also applies to: 32-33

src/domain/in-app-notification-reader/field-resolvers/in.app.notification.community.new.member.resolver.fields.ts (1)

37-37: LGTM! Consistent nullable field implementation

The space field implementation follows the same pattern as other nullable fields, maintaining consistency across resolvers.

Also applies to: 42-43

src/core/dataloader/creators/loader.creators/in-app-notification/community.type.loader.creator.ts (2)

5-8: LGTM! Clean import organization

The imports are well-organized and properly destructured for better readability.


20-25: LGTM! Proper implementation of nullable resolution support

The create method correctly implements the nullable resolution feature by:

  1. Accepting optional configuration
  2. Forwarding the resolveToNull option to the batch loader
  3. Providing proper type information
src/core/dataloader/creators/loader.creators/in-app-notification/contributor.loader.creator.ts (2)

4-7: LGTM: Type definitions and method signature changes look good!

The updated signature properly implements the nullable field support while maintaining type safety. The inclusion of EntityNotFoundException in the return type provides clear error handling semantics.

Also applies to: 15-15, 23-25


Line range hint 32-48: Review commented SQL query implementation

There's a commented SQL query that seems to handle all contributor types (User, Organization, VirtualContributor) but is currently only implementing User lookup.

Let's verify if this is intentional:

src/core/dataloader/utils/createTypedBatchLoader.ts (2)

8-14: LGTM: Well-structured function signature with proper typing

The updated signature properly handles optional configuration while maintaining type safety. The debugging options are well documented.


Line range hint 49-55: LGTM: Proper DataLoader configuration

The DataLoader configuration is correct with appropriate caching and naming options. The type definition properly includes null in the generic parameter.

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/core/dataloader/utils/createTypedRelationLoader.ts (1)

15-16: Address the TODO comment about improving types

The TODO comment indicates that the TParent type constraint needs improvement. Consider using a more specific type interface instead of the generic index signature.

Would you like me to help create a more specific type interface for the TParent type parameter?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 68f3332 and b676314.

📒 Files selected for processing (2)
  • src/core/dataloader/utils/createTypedRelationLoader.ts (1 hunks)
  • src/core/dataloader/utils/createTypedSimpleLoader.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/core/dataloader/utils/createTypedRelationLoader.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
src/core/dataloader/utils/createTypedSimpleLoader.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.

Context Files (Do Not Review):

  • docs/Design.md - Design overview of the project
  • docs/Pagination.md - Pagination design overview
  • docs/Developing.md - Development setup overview
  • docs/graphql-typeorm-usage.md - overview of GraphQL and TypeORM usage and how they are used together with NestJS in the project
  • docs/database-definitions.md - guidelines for creating TypeORM entity defnitions
  • src/core/error-handling/graphql.exception.filter.ts - GraphQL error handling
  • src/core/error-handling/http.exception.filter.ts - HTTP error handling
  • src/core/error-handling/rest.error.response.ts - REST error response
  • src/core/error-handling/unhandled.exception.filter.ts - Global exception handler

Guidelines:

  • Our project uses global exception handlers (UnhandledExceptionFilter), so avoid suggesting additional try/catch blocks unless handling specific cases.
  • Use NestJS latest documentation from https://docs.nestjs.com/ for reference on NestJS best practices.
  • Use TypeORM latest documentation from https://typeorm.io/ for reference on TypeORM best practices.
  • Refer to the design overview in the context files for better understanding.
🔇 Additional comments (5)
src/core/dataloader/utils/createTypedSimpleLoader.ts (2)

4-4: LGTM: Clean import addition

The import of EntityNotFoundException is properly added and follows the project's import conventions.


15-15: LGTM: Return type enhancement properly handles nullable fields

The return type modification to ILoader<TResult | null | EntityNotFoundException> correctly implements the PR objective by:

  • Explicitly declaring all possible return types
  • Maintaining type safety
  • Following TypeScript best practices
src/core/dataloader/utils/createTypedRelationLoader.ts (3)

8-8: LGTM: Clean import addition

The import of EntityNotFoundException is properly added and follows the project's import conventions.


23-23: LGTM: Return type enhancement properly handles nullable fields

The return type modification to ILoader<TResult | null | EntityNotFoundException> correctly implements the PR objective and maintains consistency with createTypedSimpleLoader.ts.


Line range hint 15-45: Verify the impact of nullable relations

Since the function now handles nullable relations, we should verify that the relation loading logic in findByBatchIds properly handles null cases.

✅ Verification successful

Let me analyze the implementation of findByBatchIds to verify how it handles nullable relations.


Nullable relations are properly handled in the implementation

The findByBatchIds implementation correctly handles nullable relations through the resolveToNull option:

  • When resolveToNull is true, it returns an empty object ({} as TResult) for missing relations
  • When resolveToNull is false, it throws an EntityNotFoundException
  • The option is being actively used across multiple resolvers in the codebase for handling nullable relations (e.g., in whiteboard, callout, and notification resolvers)
  • The DataLoader implementation ensures consistent length and order of results, properly mapping nulls/errors to their corresponding keys
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for findByBatchIds implementation and its tests
echo "Searching for findByBatchIds implementation:"
ast-grep --pattern 'export const findByBatchIds = $_'

echo "\nSearching for related test files:"
fd -e spec.ts -e test.ts findByBatchIds

Length of output: 4418


Script:

#!/bin/bash
# Search for tests that might cover nullable relations
rg -A 5 "resolveToNull" --type ts

# Search for any test files that might test the dataloader
fd -e spec.ts -e test.ts dataloader

Length of output: 10861

@Comoque1 Comoque1 merged commit ae6d6db into develop Dec 11, 2024
3 checks passed
@hero101 hero101 deleted the missing-in-app branch December 11, 2024 15:46
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