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

feat: migrate playground #1811

Merged
merged 8 commits into from
May 2, 2024
Merged

feat: migrate playground #1811

merged 8 commits into from
May 2, 2024

Conversation

amitksingh1490
Copy link
Collaborator

@amitksingh1490 amitksingh1490 commented Apr 30, 2024

fixes #1790

Cors enabled for tailcall.run if no cors setting is provided

@amitksingh1490 amitksingh1490 added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Apr 30, 2024
Copy link
Contributor

coderabbitai bot commented Apr 30, 2024

Walkthrough

Walkthrough

The primary change across the codebase involves removing the graphiql: true parameter from various GraphQL schema declarations, effectively disabling the GraphiQL interface in multiple server configurations. Additionally, there are adjustments in logging behavior and the redirection of users to a new playground URL upon server start.

Changes

File Path Change Summary
Various *.graphql files Removed graphiql: true from @server directives
src/blueprint/server.rs, src/cli/server/*.rs, src/http/*.rs Removal of graphiql related fields and functions
tailcall-cloudflare/src/handle.rs Deferred handling of GraphiQL requests in code flow

Assessment against linked issues

Objective Addressed Explanation
Drop the GET /graphql route (#1790)
On start, open new playground URL instead of /graphql route (#1790) The changes in logging functions and the redirection to the new playground URL align with this requirement.

The code changes effectively address the objectives outlined in the linked issue, focusing on migrating away from the GraphiQL interface towards a new playground URL approach. The systematic removal of graphiql parameters and the redirection logic support this transition seamlessly.


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between fc96336 and 74f562c.
Files ignored due to path filters (24)
  • Cargo.lock is excluded by !**/*.lock, !**/*.lock
  • Cargo.toml is excluded by !**/*.toml
  • examples/jsonplaceholder.json is excluded by !**/*.json
  • examples/jsonplaceholder.yml is excluded by !**/*.yml
  • examples/jsonplaceholder_batch.json is excluded by !**/*.json
  • examples/jsonplaceholder_batch.yml is excluded by !**/*.yml
  • tests/core/snapshots/apollo-tracing.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/auth-basic.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/auth-jwt.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/call-graphql-datasource.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/call-operator.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/grpc-batch.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/grpc-error.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/grpc-override-url-from-upstream.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/grpc-proto-with-same-package.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/grpc-reflection.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/grpc-simple.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/grpc-url-from-upstream.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/io-cache.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/jsonplaceholder-call-post.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/test-enum-default.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/test-params-as-body.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/test-scalars.md_merged.snap is excluded by !**/*.snap, !**/*.snap
  • tests/core/snapshots/test-set-cookie-headers.md_merged.snap is excluded by !**/*.snap, !**/*.snap
Files selected for processing (52)
  • README.md (1 hunks)
  • ci-benchmark/benchmark.graphql (1 hunks)
  • examples/apollo-tracing.graphql (1 hunks)
  • examples/auth.graphql (1 hunks)
  • examples/call.graphql (1 hunks)
  • examples/cors.graphql (1 hunks)
  • examples/graphql-composition.graphql (1 hunks)
  • examples/grpc-reflection.graphql (1 hunks)
  • examples/grpc.graphql (1 hunks)
  • examples/jsonplaceholder_batch.graphql (1 hunks)
  • examples/jsonplaceholder_http_2.graphql (1 hunks)
  • examples/jsonplaceholder_script.graphql (1 hunks)
  • examples/rest-api.graphql (1 hunks)
  • examples/telemetry-otlp.graphql (1 hunks)
  • examples/telemetry-prometheus.graphql (1 hunks)
  • examples/telemetry-stdout.graphql (1 hunks)
  • generated/.tailcallrc.graphql (1 hunks)
  • generated/.tailcallrc.schema.json (1 hunks)
  • src/blueprint/server.rs (2 hunks)
  • src/cli/server/http_1.rs (1 hunks)
  • src/cli/server/http_2.rs (1 hunks)
  • src/cli/server/mod.rs (1 hunks)
  • src/cli/server/server_config.rs (1 hunks)
  • src/config/server.rs (2 hunks)
  • src/data_loader/cache.rs (1 hunks)
  • src/data_loader/storage.rs (1 hunks)
  • src/http/mod.rs (2 hunks)
  • src/http/request_handler.rs (5 hunks)
  • tailcall-cloudflare/src/handle.rs (2 hunks)
  • tailcall-cloudflare/tests/cf_tests.spec.ts (2 hunks)
  • tailcall-fixtures/fixtures/configs/user-posts.graphql (1 hunks)
  • tests/execution/apollo-tracing.md (1 hunks)
  • tests/execution/auth-basic.md (1 hunks)
  • tests/execution/auth-jwt.md (1 hunks)
  • tests/execution/call-graphql-datasource.md (1 hunks)
  • tests/execution/call-operator.md (1 hunks)
  • tests/execution/grpc-batch.md (1 hunks)
  • tests/execution/grpc-error.md (1 hunks)
  • tests/execution/grpc-override-url-from-upstream.md (1 hunks)
  • tests/execution/grpc-proto-with-same-package.md (1 hunks)
  • tests/execution/grpc-reflection.md (1 hunks)
  • tests/execution/grpc-simple.md (1 hunks)
  • tests/execution/grpc-url-from-upstream.md (1 hunks)
  • tests/execution/io-cache.md (1 hunks)
  • tests/execution/jsonplaceholder-call-post.md (1 hunks)
  • tests/execution/test-duplicated-link.md (1 hunks)
  • tests/execution/test-enum-default.md (1 hunks)
  • tests/execution/test-grpc-group-by.md (1 hunks)
  • tests/execution/test-grpc-nested-data.md (1 hunks)
  • tests/execution/test-params-as-body.md (1 hunks)
  • tests/execution/test-scalars.md (1 hunks)
  • tests/execution/test-set-cookie-headers.md (1 hunks)
Files skipped from review as they are similar to previous changes (50)
  • ci-benchmark/benchmark.graphql
  • examples/apollo-tracing.graphql
  • examples/auth.graphql
  • examples/call.graphql
  • examples/cors.graphql
  • examples/graphql-composition.graphql
  • examples/grpc-reflection.graphql
  • examples/grpc.graphql
  • examples/jsonplaceholder_batch.graphql
  • examples/jsonplaceholder_http_2.graphql
  • examples/jsonplaceholder_script.graphql
  • examples/rest-api.graphql
  • examples/telemetry-otlp.graphql
  • examples/telemetry-prometheus.graphql
  • examples/telemetry-stdout.graphql
  • generated/.tailcallrc.graphql
  • generated/.tailcallrc.schema.json
  • src/blueprint/server.rs
  • src/cli/server/http_1.rs
  • src/cli/server/http_2.rs
  • src/cli/server/mod.rs
  • src/cli/server/server_config.rs
  • src/config/server.rs
  • src/data_loader/cache.rs
  • src/data_loader/storage.rs
  • src/http/mod.rs
  • tailcall-cloudflare/src/handle.rs
  • tailcall-cloudflare/tests/cf_tests.spec.ts
  • tailcall-fixtures/fixtures/configs/user-posts.graphql
  • tests/execution/apollo-tracing.md
  • tests/execution/auth-basic.md
  • tests/execution/auth-jwt.md
  • tests/execution/call-graphql-datasource.md
  • tests/execution/call-operator.md
  • tests/execution/grpc-batch.md
  • tests/execution/grpc-error.md
  • tests/execution/grpc-override-url-from-upstream.md
  • tests/execution/grpc-proto-with-same-package.md
  • tests/execution/grpc-reflection.md
  • tests/execution/grpc-simple.md
  • tests/execution/grpc-url-from-upstream.md
  • tests/execution/io-cache.md
  • tests/execution/jsonplaceholder-call-post.md
  • tests/execution/test-duplicated-link.md
  • tests/execution/test-enum-default.md
  • tests/execution/test-grpc-group-by.md
  • tests/execution/test-grpc-nested-data.md
  • tests/execution/test-params-as-body.md
  • tests/execution/test-scalars.md
  • tests/execution/test-set-cookie-headers.md
Additional Context Used
GitHub Check Runs (1)
codecov/patch failure (4)

src/http/request_handler.rs: [warning] 39-39: src/http/request_handler.rs#L39
Added line #L39 was not covered by tests


src/http/request_handler.rs: [warning] 145-165: src/http/request_handler.rs#L145-L165
Added lines #L145 - L165 were not covered by tests


src/http/request_handler.rs: [warning] 167-173: src/http/request_handler.rs#L167-L173
Added lines #L167 - L173 were not covered by tests


src/http/request_handler.rs: [warning] 175-175: src/http/request_handler.rs#L175
Added line #L175 was not covered by tests

Path-based Instructions (1)
src/http/request_handler.rs (1)

Pattern **/*.rs: Programming Style Guidelines

  • When calling functions that do not need to modify values, pass references of those values.
  • When calling functions that need to modify values, pass ownership of the values, and ensure they are returned from the function.

IMPORTANT: This programming style may not be suitable for performance-sensitive components or hot code paths. In such cases, prioritize efficiency and optimization strategies to enhance performance.

Testing

  1. Write Tests: For every new feature or bugfix, ensure that you write appropriate tests.
    Structure your tests in the following way:

    use pretty_assertions::assert_eq;
    fn test_something_important() {
       let value = setup_something_using_a_function();
    
       let actual = perform_some_operation_on_the_value(value);
       let expected = ExpectedValue {foo: 1, bar: 2};
    
       assert_eq!(actual, expected);
    }
    • Setup the value using helper methods in tests.
    • Create an actual and an expected value.
    • Assert the two values in a new line.
    • Ensure there are only one assertions per test.
Additional comments not posted (1)
README.md (1)

60-60: Ensure the removal of graphiql: true aligns with the new playground setup.


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>.
    • 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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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 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

codecov bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 16.66667% with 30 lines in your changes are missing coverage. Please review.

Project coverage is 86.90%. Comparing base (fc96336) to head (74f562c).

Files Patch % Lines
src/http/request_handler.rs 0.00% 30 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1811   +/-   ##
=======================================
  Coverage   86.89%   86.90%           
=======================================
  Files         156      156           
  Lines       15836    15840    +4     
=======================================
+ Hits        13761    13765    +4     
  Misses       2075     2075           

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

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: 2

src/http/mod.rs Outdated
@@ -15,7 +15,7 @@ pub use data_loader::*;
pub use data_loader_request::*;
pub use method::Method;
pub use request_context::RequestContext;
pub use request_handler::{graphiql, handle_request, API_URL_PREFIX};
pub use request_handler::{handle_request, API_URL_PREFIX};
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Several files in the codebase still use the graphiql function. This contradicts the PR's intention to remove it from the public API. The following files need attention:

  • src/config/server.rs
  • src/cli/server/mod.rs
  • src/cli/server/server_config.rs
  • src/blueprint/server.rs
Analysis chain

Removal of graphiql from public API aligns with the migration to an external playground.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Ensure that there are no remaining references to the `graphiql` function in the codebase.

# Search for any references to the `graphiql` function across all `.rs` files.
rg --glob '*.rs' 'graphiql' --files-with-matches

Length of output: 147

use async_graphql::ServerError;
use hyper::header::{self, CONTENT_TYPE};
use hyper::header::{self};
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring to focus on direct handling of GraphQL requests is well-implemented.

Would you like me to generate unit tests to ensure the new request handling logic works as expected?

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

Out of diff range and nitpick comments (1)
src/http/request_handler.rs (1)

Line range hint 56-85: The graphql_request function is robust, handling errors appropriately and using Arc for shared state in asynchronous tasks. The changes align well with the PR's objectives to streamline GraphQL handling.

Would you like me to generate unit tests to ensure the new request handling logic works as expected?

src/cli/server/mod.rs Outdated Show resolved Hide resolved
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

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

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

Out of diff range and nitpick comments (3)
README.md (2)

Line range hint 100-100: Consider hyphenating "first time contributor" to "first-time contributor" for grammatical correctness.


Line range hint 114-114: Add alt text to the image for better accessibility.

src/http/request_handler.rs (1)

Line range hint 46-46: Handling of REST API requests is well-implemented, integrating seamlessly with the application context. Consider adding more detailed logging for better traceability.

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

Copy link

github-actions bot commented May 2, 2024

🐰Bencher

ReportThu, May 2, 2024 at 16:44:40 UTC
Projecttailcall
Branch1811/merge
Testbedbenchmarking-runner
Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns) | (Δ%)
Latency Upper Boundary
nanoseconds (ns) | (%)
group_by✅ (view plot)600.76 (-1.29%)634.74 (94.65%)
input/args.missing✅ (view plot)25.48 (+0.68%)26.18 (97.33%)
input/args.nested.existing✅ (view plot)55.90 (-0.62%)58.24 (95.98%)
input/args.nested.missing✅ (view plot)38.11 (-2.42%)39.95 (95.40%)
input/args.root✅ (view plot)52.79 (+0.02%)54.50 (96.86%)
input/headers.existing✅ (view plot)31.67 (+0.42%)31.84 (99.45%)
input/headers.missing✅ (view plot)30.05 (-1.25%)31.19 (96.34%)
input/value.missing✅ (view plot)23.42 (-0.63%)24.99 (93.75%)
input/value.nested.existing✅ (view plot)42.47 (+3.59%)42.79 (99.25%)
input/value.nested.missing✅ (view plot)36.71 (+2.61%)37.35 (98.30%)
input/value.root✅ (view plot)38.80 (+0.37%)39.87 (97.33%)
input/vars.existing✅ (view plot)8.39 (-0.61%)8.86 (94.70%)
input/vars.missing✅ (view plot)8.06 (-1.17%)8.99 (89.65%)
test_batched_body✅ (view plot)2,820.20 (-99.83%)2,375,940.33 (0.12%)
test_batched_body #2✅ (view plot)1,829,900.00 (+0.32%)1,871,779.92 (97.76%)
test_data_loader✅ (view plot)484,320.00 (+2.53%)489,812.25 (98.88%)
with_mustache_expressions✅ (view plot)1,173.30 (+0.57%)1,223.96 (95.86%)
with_mustache_literal✅ (view plot)699.83 (-3.17%)759.95 (92.09%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

@amitksingh1490 amitksingh1490 force-pushed the fix/1790 branch 2 times, most recently from 579e656 to 2a8b6b0 Compare May 2, 2024 15:47
@tusharmath tusharmath enabled auto-merge (squash) May 2, 2024 16:42
@tusharmath tusharmath disabled auto-merge May 2, 2024 16:43
@tusharmath tusharmath merged commit 97dc20f into main May 2, 2024
28 of 31 checks passed
@tusharmath tusharmath deleted the fix/1790 branch May 2, 2024 16:44
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

Comment on lines +145 to +174
async fn handle_origin_tailcall<T: DeserializeOwned + GraphQLRequestLike>(
req: Request<Body>,
app_ctx: Arc<AppContext>,
request_counter: &mut RequestCounter,
) -> Result<Response<Body>> {
let method = req.method();
if method == Method::OPTIONS {
let mut res = Response::new(Body::default());
res.headers_mut().insert(
header::ACCESS_CONTROL_ALLOW_ORIGIN,
HeaderValue::from_static("https://tailcall.run"),
);
res.headers_mut().insert(
header::ACCESS_CONTROL_ALLOW_METHODS,
HeaderValue::from_static("GET, POST, OPTIONS"),
);
res.headers_mut().insert(
header::ACCESS_CONTROL_ALLOW_HEADERS,
HeaderValue::from_static("*"),
);
Ok(res)
} else {
let mut res = handle_request_inner::<T>(req, app_ctx, request_counter).await?;
res.headers_mut().insert(
header::ACCESS_CONTROL_ALLOW_ORIGIN,
HeaderValue::from_static("https://tailcall.run"),
);

Ok(res)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the new CORS handling for tailcall.run is thoroughly tested.

#!/bin/bash
# Description: Verify that the new CORS handling logic in `handle_origin_tailcall` is covered by tests.

# Find test files related to `request_handler.rs` and search for tests covering the new CORS logic.
fd 'request_handler.rs' --exec rg --files-with-matches --type rust $'test.*handle_origin_tailcall'

ssddOnTop pushed a commit that referenced this pull request May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci: benchmark Runs benchmarks type: feature Brand new functionality, features, pages, workflows, endpoints, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: migrate playground
2 participants