Giveth / impact-graph

MIT License
47 stars 16 forks source link

use networkId instead of optimism-only flag #1653

Closed ae2079 closed 1 week ago

ae2079 commented 1 week ago

Summary by CodeRabbit

coderabbitai[bot] commented 1 week ago

Walkthrough

The recent changes involve replacing the fromOptimismOnly boolean parameter with a more flexible networkId numeric parameter across various parts of the codebase. This shift, applied to donation and project repositories, resolvers, and test GraphQL queries, enables filtering by specific network IDs instead of using a simpler optimism flag. This update increases the granularity and flexibility of network-based queries and functionality.

Changes

Files Change Summary
src/repositories/donationRepository.ts Replaced fromOptimismOnly parameter with networkId in functions for calculating donation metrics.
src/repositories/projectRepository.ts Replaced includesOptimism parameter with networkId in functions for retrieving project metrics.
src/resolvers/donationResolver.ts Updated method arguments to use networkId instead of fromOptimismOnly for filtering donations by network.
src/resolvers/projectResolver.ts Replaced includesOptimism parameter with networkId for project-related methods in the resolver.
test/graphqlQueries.ts Renamed query parameters from includesOptimism and fromOptimismOnly to networkId in multiple GraphQL queries used for testing.

Poem

Amidst the networks old and new,
Where donations sparkle, in vibrant hue,
No more flags to check Optimism's cheer,
A numeric path, now crystal clear.
Projects thrive and totals rise,
With networkId, we’re wise,
In data's scope, joy multiplies.


Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 91012571560e627af5ff328272378bff37e7709f and 6fe5fb09d033b3016af330e216d5721e664f6e4f.
Files selected for processing (5) * src/repositories/donationRepository.ts (17 hunks) * src/repositories/projectRepository.ts (5 hunks) * src/resolvers/donationResolver.ts (7 hunks) * src/resolvers/projectResolver.ts (2 hunks) * test/graphqlQueries.ts (5 hunks)
Files skipped from review due to trivial changes (1) * test/graphqlQueries.ts
Additional context used
Biome
src/resolvers/donationResolver.ts
[error] 231-231: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 232-232: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 265-265: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 266-266: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 267-267: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 268-268: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 319-319: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 320-320: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 321-321: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 322-322: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 356-356: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 357-357: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 358-358: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 359-359: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 397-397: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 405-405: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 406-406: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 407-407: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 433-433: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 434-434: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file.
src/resolvers/projectResolver.ts
[error] 653-653: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 655-655: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 689-689: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 705-705: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 719-719: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 795-795: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 797-797: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 831-831: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 832-832: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 834-834: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 835-835: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 910-910: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 911-911: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 913-913: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 914-914: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 1047-1047: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 1048-1048: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 1049-1049: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 1208-1208: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file. --- [error] 1209-1209: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file.
Additional comments not posted (6)
src/resolvers/donationResolver.ts (4)
`297-301`: **Conditional query construction** The conditional logic for constructing the query based on `networkId` is well implemented. It ensures that the `networkId` filter is correctly applied whether other date filters are present or not. This is crucial for maintaining the correct logic flow and ensuring accurate data retrieval based on the network ID. --- Line range hint `321-339`: **Ensure consistent error handling** The method `donationsTotalUsdPerDate` correctly uses the `networkId` parameter to filter donations. However, ensure that error handling is consistent across all query methods. It's good practice to log and rethrow the error, as done here, to maintain transparency in error management. --- `267-267`: **Correct decorator usage for method parameter** The `@Arg('networkId', { nullable: true })` decorator is used correctly here to define a method parameter. However, the static analysis tool flagged an error about decorators not being valid here. This might be a configuration issue or a false positive, as decorators are commonly used in `type-graphql`.
Verification successful --- **Parameter decorator configuration is correct** The `tsconfig.json` file contains the `experimentalDecorators` setting enabled, which supports the usage of decorators like `@Arg` in `type-graphql`. - `tsconfig.json`: ```json "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */ ``` This confirms that the `@Arg` decorator is configured correctly in the TypeScript setup.
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Check if parameter decorators are enabled in the TypeScript configuration. cat tsconfig.json | jq '.compilerOptions.experimentalDecorators' ``` Length of output: 121 --- --- Script: ```shell #!/bin/bash # Locate the tsconfig.json file and validate its JSON structure fd --type f --name tsconfig.json --exec jq empty {} # Check the experimentalDecorators setting in the tsconfig.json file fd --type f --name tsconfig.json --exec jq '.compilerOptions.experimentalDecorators' {} ``` Length of output: 647 --- --- Script: ```shell #!/bin/bash # Locate the tsconfig.json file fd tsconfig.json # Check the experimentalDecorators setting in the tsconfig.json file jq '.compilerOptions.experimentalDecorators' tsconfig.json ``` Length of output: 148 --- --- Script: ```shell #!/bin/bash # Output the contents of the tsconfig.json file to inspect for errors cat tsconfig.json ``` Length of output: 5148
Tools
Biome
[error] 267-267: Decorators are not valid here. (parse) Decorators are only valid on class declarations, class expressions, and class methods. You can enable parameter decorators by setting the `unsafeParameterDecoratorsEnabled` option to `true` in your configuration file.
--- Line range hint `358-376`: **Check for correct implementation of network filtering** The method `totalDonationsNumberPerDate` includes changes for `networkId` handling. It's important to verify that the implementation aligns with the intended business logic, especially when handling conditional queries based on network ID.
Verification successful --- **Check for correct implementation of network filtering** The `totalDonationsNumberPerDate` method in `src/resolvers/donationResolver.ts` does indeed handle the `networkId` parameter. It correctly passes `networkId` to the `donationsNumberPerDateRange` and `donationsTotalNumberPerDateRangeByMonth` functions, ensuring that network filtering is applied as expected. - **File**: `src/resolvers/donationResolver.ts` - **Method**: `totalDonationsNumberPerDate` - **Lines**: 366-379
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify the correct implementation of network filtering in the donation queries. ast-grep --lang typescript --pattern $'class DonationResolver { $$$ totalDonationsNumberPerDate($_, $_, $_, $_) { $$$ } $$$ }' ``` Length of output: 141 --- --- Script: ```shell #!/bin/bash # Search for the `totalDonationsNumberPerDate` method in the entire codebase. rg 'totalDonationsNumberPerDate' ``` Length of output: 848 --- Script: ```shell #!/bin/bash # Verify the handling of `networkId` within the `totalDonationsNumberPerDate` method. ast-grep --lang typescript --pattern $'function totalDonationsNumberPerDate($_, $_, $networkId, $_) { $$$ }' ``` Length of output: 111 --- --- Script: ```shell #!/bin/bash # Display the implementation of the `totalDonationsNumberPerDate` method in `src/resolvers/donationResolver.ts`. ast-grep --lang typescript --pattern $'async totalDonationsNumberPerDate($_, $_, $_, $_) { $$$ }' src/resolvers/donationResolver.ts ``` Length of output: 616 --- --- Script: ```shell #!/bin/bash # Display the implementation of the `totalDonationsNumberPerDate` method in `src/resolvers/donationResolver.ts` with corrected pattern. ast-grep --lang typescript --pattern $'async totalDonationsNumberPerDate($_, $_, $_, $_): Promise<$_> { $$$ }' src/resolvers/donationResolver.ts ``` Length of output: 642 --- --- Script: ```shell #!/bin/bash # Display the implementation of the `totalDonationsNumberPerDate` method in `src/resolvers/donationResolver.ts` using `cat` and `awk`. awk '/async totalDonationsNumberPerDate/,/^\}/' src/resolvers/donationResolver.ts ``` Length of output: 20192
src/resolvers/projectResolver.ts (2)
Line range hint `1294-1311`: **Updated method parameters to use `networkId`.** The changes correctly replace the `includesOptimism` boolean with the more flexible `networkId` integer. This allows for more granular control over which network's data is queried, which aligns with the PR's objectives. --- Line range hint `653-653`: **Invalid use of decorators reported by static analysis.** The static analysis tool has identified multiple lines where decorators are incorrectly applied. This issue typically arises due to a misconfiguration in the TypeScript compiler options. Ensure that the `experimentalDecorators` and `emitDecoratorMetadata` options are enabled in your `tsconfig.json`. If these options are already enabled, this may be a false positive from the static analysis tool. Also applies to: 655-655, 689-689, 705-705, 719-719, 795-795, 797-797, 831-831, 832-832, 834-834, 835-835, 910-910, 911-911, 913-913, 914-914, 1047-1047, 1048-1048, 1049-1049, 1208-1208, 1209-1209
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 Configration 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
ae2079 commented 1 week ago

related to this issue: https://github.com/Giveth/analytics-dashboard/issues/9 and should be merge before this PR: https://github.com/Giveth/analytics-dashboard/pull/12