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(torii): graphql playground URL #2707

Merged
merged 4 commits into from
Nov 21, 2024
Merged

fix(torii): graphql playground URL #2707

merged 4 commits into from
Nov 21, 2024

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Nov 21, 2024

Summary by CodeRabbit

  • New Features

    • Improved construction of GraphQL and WebSocket endpoints for better clarity and organization.
    • Enhanced error messaging for invalid URL schemes.
  • Bug Fixes

    • Streamlined logic for determining endpoints, ensuring consistent URL handling.

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

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

Please upload report for BASE (main@d005475). Learn more about missing BASE report.
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/graphql/src/server.rs 0.00% 12 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2707   +/-   ##
=======================================
  Coverage        ?   56.26%           
=======================================
  Files           ?      410           
  Lines           ?    52848           
  Branches        ?        0           
=======================================
  Hits            ?    29735           
  Misses          ?    23113           
  Partials        ?        0           

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


🚨 Try these New Features:

@glihm glihm marked this pull request as ready for review November 21, 2024 02:18
@glihm glihm requested a review from Larkooo November 21, 2024 02:18
Copy link
Collaborator Author

@glihm glihm left a comment

Choose a reason for hiding this comment

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

@Larkooo I guess we also want to use the external URL in the playground?

@steebchen, since there is this external-url, we need to provide it to torii.

Copy link

coderabbitai bot commented Nov 21, 2024

Walkthrough

Ohayo, sensei! The recent changes focus on refining the graphql_filter function within crates/torii/graphql/src/server.rs. The modifications enhance how GraphQL and WebSocket endpoints are constructed by utilizing a tuple format based on the external_url. The new implementation clarifies the scheme handling and error messaging for invalid URLs while streamlining the logic for generating the endpoints. The playground filter now references the newly defined endpoint variables instead of hardcoded strings, maintaining the function's overall structure and functionality.

Changes

File Path Change Summary
crates/torii/graphql/src/server.rs Refactored graphql_filter to construct GraphQL and WebSocket endpoints using a tuple format based on external_url. Clarified scheme handling and error messages for invalid URLs. Updated playground filter to use new endpoint variables instead of hardcoded strings.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    Client->>Server: Request GraphQL Endpoint
    Server-->>Client: Return GraphQL URL
    Client->>Server: Request WebSocket Endpoint
    Server-->>Client: Return WebSocket URL
Loading

🪧 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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d005475 and 7be2959.

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

63-65: LGTM! Default paths follow conventions.

The fallback paths "graphql" and "graphql/ws" align with common GraphQL server conventions.


71-72: Ohayo! Verify the playground endpoints are working.

The implementation correctly uses the constructed endpoints for the GraphiQL playground.

Let's verify the GraphQL playground is accessible:

✅ Verification successful

The previous result shows only one occurrence of the WebSocket endpoint, but let's verify the complete endpoint configuration and any WebSocket-related setup to ensure there are no conflicts or misconfigurations.


I need to verify how these endpoints are constructed and ensure they're properly configured in the GraphiQL setup before making a final determination.


I need to see the complete logic for how both endpoints are constructed, including the fallback case when external_url is None, to make a final determination about the playground configuration.


Ohayo! The playground endpoints are properly configured, sensei!

The implementation correctly handles both scenarios:

  • For external URLs: Properly transforms HTTP/HTTPS URLs to their WS/WSS counterparts for subscriptions
  • For local setup: Uses "graphql" for queries and "graphql/ws" for subscriptions

The endpoint construction is robust and matches the GraphiQL playground configuration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the GraphQL playground endpoint is properly configured
# Test: Search for any hardcoded GraphQL endpoints that might conflict
rg -g '!target/' -g '*.rs' 'graphql/ws|ws/graphql' .

Length of output: 149


Script:

#!/bin/bash
# Let's check the full context of the GraphQL endpoint configuration
rg -g '!target/' -g '*.rs' -B 5 -A 5 'endpoint\(' .

# Also check for any WebSocket related configurations
rg -g '!target/' -g '*.rs' 'WebSocket|ws_config' .

Length of output: 5821


Script:

#!/bin/bash
# Let's check how the endpoints are constructed
rg -g '!target/' -g '*.rs' -B 10 -A 3 'let.*graphql_endpoint|let.*subscription_endpoint' .

# And verify the GraphiQL source configuration
ast-grep --pattern 'GraphiQLSource::build()$$$'

Length of output: 1113


Script:

#!/bin/bash
# Let's see the complete endpoint construction logic
rg -g '!target/' -g '*.rs' -C 20 'let \(graphql_endpoint, subscription_endpoint\)' .

Length of output: 3009

Comment on lines +51 to +61
let (graphql_endpoint, subscription_endpoint) = if let Some(external_url) = external_url {
let mut graphql_url = external_url;
graphql_url.set_path("graphql");

let websocket_scheme = match websocket_url.scheme() {
"http" => "ws",
let mut websocket_url = graphql_url.clone();
websocket_url.set_path("ws");
let _ = websocket_url.set_scheme(match websocket_url.scheme() {
"https" => "wss",
_ => panic!("Invalid URL scheme"), // URL validated on input so this never hits
};
"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.

⚠️ Potential issue

Ohayo sensei! Replace panic with proper error handling.

The URL scheme handling currently uses panic! which could crash the server in production. Consider returning a Result instead.

Here's a suggested improvement:

-    let (graphql_endpoint, subscription_endpoint) = if let Some(external_url) = external_url {
-        let mut graphql_url = external_url;
-        graphql_url.set_path("graphql");
-
-        let mut websocket_url = graphql_url.clone();
-        websocket_url.set_path("ws");
-        let _ = websocket_url.set_scheme(match websocket_url.scheme() {
-            "https" => "wss",
-            "http" => "ws",
-            _ => panic!("Invalid URL scheme - must be http or https"),
-        });
+    let (graphql_endpoint, subscription_endpoint) = if let Some(external_url) = external_url {
+        let mut graphql_url = external_url;
+        graphql_url.set_path("graphql");
+
+        let mut websocket_url = graphql_url.clone();
+        websocket_url.set_path("ws");
+        let ws_scheme = match websocket_url.scheme() {
+            "https" => "wss",
+            "http" => "ws",
+            scheme => {
+                log::error!("Invalid URL scheme '{}' - must be http or https", scheme);
+                return warp::reply::with_status(
+                    "Invalid URL scheme",
+                    warp::http::StatusCode::INTERNAL_SERVER_ERROR,
+                );
+            }
+        };
+        websocket_url.set_scheme(ws_scheme).expect("valid scheme");

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

Copy link
Contributor

@steebchen steebchen left a comment

Choose a reason for hiding this comment

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

lgtm. we should also make sure it'll work for WS.

@glihm
Copy link
Collaborator Author

glihm commented Nov 21, 2024

@Larkooo if sounds good to you we could move on and integrate with slot. 👍

@glihm glihm merged commit 374461d into main Nov 21, 2024
14 checks passed
@glihm glihm deleted the fix/graphql-pgnd branch November 21, 2024 21:04
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