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: fix graphql playground URL #2737

Merged
merged 1 commit into from
Nov 29, 2024
Merged

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Nov 29, 2024

Summary by CodeRabbit

  • New Features
    • Improved URL handling for GraphQL and WebSocket endpoints, allowing direct use of external URLs without appending additional paths.
    • Enhanced clarity and correctness in URL construction for both external and local server configurations.

External url is now expected to be the graphql
url. Where the websocket may be added.
Copy link

coderabbitai bot commented Nov 29, 2024

Walkthrough

Ohayo, sensei! This pull request modifies the graphql_filter function in crates/torii/graphql/src/server.rs. The changes streamline how GraphQL and WebSocket URLs are constructed based on the presence of an external URL. When an external URL is provided, it is used directly without appending "/graphql". The WebSocket URL is formed by adding "/ws" to the external URL's path. If no external URL is given, the default behavior appends "/graphql" or "/graphql/ws" to the local server's URL. Additionally, some variable declarations were simplified for clarity.

Changes

File Path Change Summary
crates/torii/graphql/src/server.rs Modified graphql_filter to adjust URL construction for GraphQL and WebSocket endpoints based on external URL presence. Simplified variable declarations and URL handling logic.

Possibly related PRs

  • fix(torii): graphql playground URL #2707: The changes in this PR also modify the graphql_filter function in the same file, focusing on the construction of GraphQL and WebSocket URLs based on the external_url, which directly relates to the modifications made in the main PR.

Suggested reviewers

  • Larkooo
  • steebchen

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

@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 (1)
crates/torii/graphql/src/server.rs (1)

64-66: Consider using constants for endpoint paths, sensei!

The hardcoded strings could be moved to constants at the module level for better maintainability.

+const LOCAL_GRAPHQL_ENDPOINT: &str = "graphql";
+const LOCAL_WS_ENDPOINT: &str = "graphql/ws";
+
 // ...
-        ("graphql".to_string(), "graphql/ws".to_string())
+        (LOCAL_GRAPHQL_ENDPOINT.to_string(), LOCAL_WS_ENDPOINT.to_string())
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cd80507 and 80e5278.

📒 Files selected for processing (1)
  • crates/torii/graphql/src/server.rs (1 hunks)
🔇 Additional comments (2)
crates/torii/graphql/src/server.rs (2)

51-52: Ohayo! The comment accurately explains the behavioral change.

The comment clearly documents why we don't append "/graphql" anymore when using an external URL.


54-62: Verify URL handling with different GraphQL clients.

The URL construction changes might affect various GraphQL clients differently. Let's verify the usage patterns in the codebase.

✅ Verification successful

Based on the search results, I can now generate the final response as the code shows consistent URL handling patterns:

URL construction is correctly implemented for both local and external GraphQL endpoints

The codebase handles URL construction consistently:

  • For external URLs (external_url provided), it preserves the original path and only appends /ws for WebSocket
  • For local URLs, it uses the standard /graphql and /graphql/ws paths
  • All GraphQL clients in the codebase use these paths consistently through the proxy handler

The changes are safe and follow established patterns used by GraphQL clients.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for GraphQL client implementations and URL usage patterns
rg -A 5 "graphql|GraphQL" --type rust

# Look for any hardcoded GraphQL paths that might need updating
rg "/graphql" --type rust

Length of output: 55652

Comment on lines +56 to 61
websocket_url.set_path(&format!("{}/ws", websocket_url.path()));
let _ = websocket_url.set_scheme(match websocket_url.scheme() {
"https" => "wss",
"http" => "ws",
_ => panic!("Invalid URL scheme - must be http or https"),
});
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider more graceful error handling for URL schemes, sensei!

The current implementation panics on invalid URL schemes. Consider returning a Result instead to handle this more gracefully.

-            _ => panic!("Invalid URL scheme - must be http or https"),
+            scheme => Err(format!("Invalid URL scheme '{}' - must be http or https", scheme))?

Committable suggestion skipped: line range outside the PR's diff.

Copy link

codecov bot commented Nov 29, 2024

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 56.47%. Comparing base (cd80507) to head (80e5278).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/graphql/src/server.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2737   +/-   ##
=======================================
  Coverage   56.47%   56.47%           
=======================================
  Files         421      421           
  Lines       53976    53974    -2     
=======================================
+ Hits        30482    30484    +2     
+ Misses      23494    23490    -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@glihm glihm merged commit 0fe329a into dojoengine:main Nov 29, 2024
13 of 14 checks passed
augustin-v pushed a commit to augustin-v/dojo that referenced this pull request Dec 4, 2024
External url is now expected to be the graphql
url. Where the websocket may be added.
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.

1 participant