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

fix(Web): separate-batchers #1867

Merged
merged 3 commits into from
Jan 30, 2025
Merged

fix(Web): separate-batchers #1867

merged 3 commits into from
Jan 30, 2025

Conversation

Harman-singh-waraich
Copy link
Contributor

@Harman-singh-waraich Harman-singh-waraich commented Jan 29, 2025

PR-Codex overview

This PR refactors the executor function in GraphqlBatcher.tsx to introduce separate batching executors for core and dispute template GraphQL requests, enhancing code clarity and modularity.

Detailed summary

  • Replaced the executor function with a fetch function that accepts url, document, and variables.
  • Created coreExecutor and dtrExecutor for handling core and dispute template requests, respectively.
  • Introduced coreBatchExec and dtrBatchExec using the new executors.
  • Updated the fetcher function to use the new batching executors based on the isDisputeTemplate flag.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Refactor
    • Improved GraphQL request execution logic by introducing separate executors for core and dispute template requests.
    • Enhanced batching mechanism to handle different types of GraphQL queries more efficiently.

@Harman-singh-waraich Harman-singh-waraich requested a review from a team as a code owner January 29, 2025 13:43
Copy link
Contributor

coderabbitai bot commented Jan 29, 2025

Walkthrough

The pull request modifies the GraphQL batching logic in the GraphqlBatcher.tsx file. The changes introduce two distinct executors: coreExecutor and dtrExecutor, each handling different types of GraphQL requests. The fetcher function has been updated to use these new executors based on the isDisputeTemplate property. The modifications aim to provide a more structured approach to handling GraphQL requests with separate execution paths for core and dispute template queries.

Changes

File Change Summary
web/src/context/GraphqlBatcher.tsx - Renamed executor to coreExecutor
- Added new dtrExecutor function
- Replaced batchExec with coreBatchExec
- Added dtrBatchExec
- Modified fetcher to use different executors based on query type

Possibly related PRs

Suggested labels

Type: Enhancement :sparkles:, Package: Web

Suggested reviewers

  • alcercu

Poem

🐰 Hop, hop, through GraphQL's maze,
Two executors dance their ways,
Core and DTR, side by side,
Batching queries with rabbit pride!
Code leaps forward, clean and bright 🚀


🪧 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. (Beta)
  • @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 or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

Copy link

netlify bot commented Jan 29, 2025

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit 07137fd
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/679b77b87bd23a00089a3a44
😎 Deploy Preview https://deploy-preview-1867--kleros-v2-testnet-devtools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 29, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 07137fd
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/679b77b8a3ca76000833e184
😎 Deploy Preview https://deploy-preview-1867--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 29, 2025

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit 07137fd
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/679b77b8bbc5710008c1a205
😎 Deploy Preview https://deploy-preview-1867--kleros-v2-university.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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 comments (1)
web/src/context/GraphqlBatcher.tsx (1)

Line range hint 25-39: Improve error handling and type safety in coreExecutor.

The current implementation has several areas for improvement:

  1. The @ts-ignore comment suggests underlying type issues that should be addressed properly.
  2. Returning an empty object on error could silently mask issues.
  3. The error message lacks specific details about what went wrong.

Consider this improved implementation:

 const coreExecutor: AsyncExecutor = async ({ document, variables }) => {
   try {
-    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
-    //@ts-ignore
     const result = request(getGraphqlUrl(false), document, variables).then((res) => ({
       data: res,
     })) as Promise<ExecutionResult>;
 
     return result;
   } catch (error) {
-    console.error("Graph error: ", { error });
-    debounceErrorToast("Graph query error: failed to fetch data.");
-    return { data: {} };
+    const errorMessage = error instanceof Error ? error.message : 'Unknown error';
+    console.error("Core GraphQL error:", { error, document, variables });
+    debounceErrorToast(`Core GraphQL query failed: ${errorMessage}`);
+    throw error; // Re-throw to allow proper error handling upstream
   }
 };
🧹 Nitpick comments (1)
web/src/context/GraphqlBatcher.tsx (1)

57-71: Consider adding error boundaries and improving type safety.

The batch execution setup looks good, but could benefit from additional error handling and type safety improvements.

Consider these enhancements:

 const coreBatchExec = createBatchingExecutor(coreExecutor);
 const dtrBatchExec = createBatchingExecutor(dtrExecutor);
 
-const fetcher = async (queries: IQuery[]) => {
+const fetcher = async (queries: readonly IQuery[]): Promise<Array<{ id: string; result: unknown }>> => {
   const batchdata = await Promise.all(
     queries.map(({ document, variables, isDisputeTemplate }) =>
-      isDisputeTemplate
-        ? dtrBatchExec({
-            document,
-            variables,
-          })
-        : coreBatchExec({
-            document,
-            variables,
-          })
+      (isDisputeTemplate ? dtrBatchExec : coreBatchExec)({
+        document,
+        variables,
+      }).catch(error => ({
+        data: null,
+        errors: [{ message: error.message }]
+      }))
     )
   );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 474605b and 4f12c3f.

📒 Files selected for processing (1)
  • web/src/context/GraphqlBatcher.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: contracts-testing
  • GitHub Check: Analyze (javascript)
  • GitHub Check: SonarCloud
🔇 Additional comments (1)
web/src/context/GraphqlBatcher.tsx (1)

29-29: Verify URL security and CORS configuration.

The separation of URLs for core and DTR operations requires careful security consideration.

Please verify:

  1. The URL configurations in both environments
  2. CORS settings for both endpoints
  3. Any authentication differences between endpoints

Also applies to: 45-45

Copy link

netlify bot commented Jan 29, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 07137fd
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/679b77b8f0f3830008c5964e
😎 Deploy Preview https://deploy-preview-1867--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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 comments (1)
web/src/context/GraphqlBatcher.tsx (1)

Line range hint 25-39: Improve error handling and type safety in the fetch function.

The current implementation has several issues:

  1. Silently returning empty data on error can mask problems and make debugging difficult
  2. Missing type annotations for parameters
  3. Using @ts-ignore is not recommended

Consider this improved implementation:

-const fetch = async (url, document, variables) => {
+const fetch = async (
+  url: string,
+  document: TypedDocumentNode<any, any>,
+  variables: Record<string, any>
+): Promise<ExecutionResult> => {
   try {
-    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
-    //@ts-ignore
     const result = request(url, document, variables).then((res) => ({
       data: res,
     })) as Promise<ExecutionResult>;
 
     return result;
   } catch (error) {
     console.error("Graph error: ", { error });
     debounceErrorToast("Graph query error: failed to fetch data.");
-    return { data: {} };
+    throw error; // Propagate the error instead of silently returning empty data
   }
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f12c3f and 9616df8.

📒 Files selected for processing (1)
  • web/src/context/GraphqlBatcher.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: contracts-testing
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
web/src/context/GraphqlBatcher.tsx (2)

41-47: Reduce code duplication between executors.

The executors are nearly identical, differing only in the URL parameter. This violates the DRY principle.


49-50: LGTM! Clean separation of batch executors.

The separation of core and DTR batch executors is well-implemented and provides a clear distinction between different types of queries.

Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

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

lgtm

@alcercu alcercu enabled auto-merge January 29, 2025 13:59
@alcercu alcercu added this pull request to the merge queue Jan 29, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jan 29, 2025
@alcercu alcercu enabled auto-merge January 30, 2025 12:59
Copy link

codeclimate bot commented Jan 30, 2025

Code Climate has analyzed commit 07137fd and detected 60 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 6
Duplication 14
Style 40

View more on Code Climate.

@alcercu alcercu merged commit 2730163 into dev Jan 30, 2025
16 of 18 checks passed
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