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

[v0] Add integration test for a complex URL as an endpoint for JSON Schema handler #8393

Merged
merged 1 commit into from
Feb 19, 2025

Conversation

ardatan
Copy link
Owner

@ardatan ardatan commented Feb 18, 2025

Tests if a complex URL is handled correctly by JSON Schema handler;
This complex URL contains;

  • No pathname /pathname
  • A username and a password username:password@domain
  • Port localhost:PORT
  • Query parameters ?queryparam=value

Summary by CodeRabbit

  • New Features

    • Introduced enhanced configuration supporting JSON Schema-based operations with an endpoint that handles authentication and query parameters.
    • Launched a new local HTTP server that returns structured JSON responses.
    • Added a private package with build and start scripts for easier local integration and execution.
    • Included a tailored sandbox configuration for a Node.js environment.
    • Added a new JSON object for authorization and URL request structure.
  • Tests

    • Developed a new test suite to verify that query operations return the expected authorization and URL details.
  • Chores

    • Updated the build process to incorporate the new workspace in artifact generation.

Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request introduces a new JSON Schema configuration in the examples/json-schema-complex-url directory. It adds configuration files, assets, source code for an HTTP server, and a test suite that verifies a "GetData" query operation. A new package with build and start scripts is created, and the root build script is updated to include the new workspace. The changes detail an upstream source with authentication, a sample JSON response, and corresponding tests while incorporating a sandbox configuration for a Node.js environment.

Changes

File(s) Change Summary
examples/json-schema-complex-url/.meshrc.yml New Mesh configuration introducing an upstream source with a JSON Schema handler; defines a GET Query operation getData with query parameters and response mapping.
examples/json-schema-complex-url/assets/getData.json New JSON asset providing a sample response with authorization and url fields for the getData operation.
examples/json-schema-complex-url/package.json New package declaration with build/start scripts, dependencies (@graphql-mesh/cli, @graphql-mesh/json-schema, graphql), and development dependencies.
examples/json-schema-complex-url/sandbox.config.json New sandbox configuration specifying a Node.js template and container version 16.
examples/json-schema-complex-url/src/index.ts New HTTP server built using Node's HTTP module on port 8515 that responds with JSON containing request details.
examples/json-schema-complex-url/tests/json-schema-complex-url.test.ts New test suite that initializes a Mesh instance, executes a GraphQL query (GetData), and verifies correct handling of authorization and query parameters.
package.json (root) Updated build-test-artifacts script to include the workspace build for @examples/json-schema-complex-url.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Suite
    participant M as Mesh Instance
    participant S as HTTP Server
    participant A as Assets (getData.json)
    T->>M: Invoke GetData Query with parameter (some_arg)
    M->>S: Forward GET request with query parameters
    S->>S: Process request (apply auth, extract URL)
    S-->>M: Return JSON response with authorization and URL
    M-->>T: Relay GetDataResponse
Loading

Suggested reviewers

  • dotansimha

Poem

I'm a little rabbit in the code burrow,
Hopping through changes neat and new,
Carrots of config and a server that sings,
Tests and scripts—to each, a fresh view,
With a joyful twitch and digital cheer,
I celebrate these updates with a hop and a cheer!
🥕🐇

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

examples/json-schema-complex-url/src/index.ts

Oops! Something went wrong! :(

ESLint: 9.20.1

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

examples/json-schema-complex-url/tests/json-schema-complex-url.test.ts

Oops! Something went wrong! :(

ESLint: 9.20.1

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f989c74 and b77842b.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (7)
  • examples/json-schema-complex-url/.meshrc.yml (1 hunks)
  • examples/json-schema-complex-url/assets/getData.json (1 hunks)
  • examples/json-schema-complex-url/package.json (1 hunks)
  • examples/json-schema-complex-url/sandbox.config.json (1 hunks)
  • examples/json-schema-complex-url/src/index.ts (1 hunks)
  • examples/json-schema-complex-url/tests/json-schema-complex-url.test.ts (1 hunks)
  • package.json (1 hunks)

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

@ardatan ardatan force-pushed the test-json-schema-hostname branch from a9f75af to f989c74 Compare February 18, 2025 11:56
Copy link
Contributor

github-actions bot commented Feb 18, 2025

Apollo Federation Subgraph Compatibility Results

Federation 1 Support Federation 2 Support
_service🟢
@key (single)🟢
@key (multi)🟢
@key (composite)🟢
repeatable @key🟢
@requires🟢
@provides🟢
federated tracing🟢
@link🟢
@shareable🟢
@tag🟢
@override🟢
@inaccessible🟢
@composeDirective🟢
@interfaceObject🟢

Learn more:

Copy link
Contributor

github-actions bot commented Feb 18, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-mesh/apollo-link 0.105.19-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/cli 0.98.24-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/config 0.106.24-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/http 0.105.19-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/migrate-config-cli 1.4.16-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/runtime 0.105.19-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/urql-exchange 0.105.19-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-live-query 0.103.18-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-newrelic 0.103.18-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-operation-field-permissions 0.103.18-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-rate-limit 0.103.18-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-response-cache 0.103.20-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-statsd 0.103.18-alpha-20250219081133-b77842b3ba576c07c73a0e351199c422278d2494 npm ↗︎ unpkg ↗︎

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

🧹 Nitpick comments (2)
examples/json-schema-complex-url/src/index.ts (2)

3-11: Add error handling for edge cases.

The server implementation should handle potential errors:

  • Request parsing errors
  • JSON serialization errors
 export default createServer((req, res) => {
+  try {
     res.writeHead(200, { 'Content-Type': 'application/json' });
     res.end(
       JSON.stringify({
         authorization: req.headers.authorization,
         url: req.url,
       }),
     );
+  } catch (error) {
+    console.error('Error processing request:', error);
+    res.writeHead(500, { 'Content-Type': 'application/json' });
+    res.end(JSON.stringify({ error: 'Internal server error' }));
+  }
 }).listen(8515, () => {

11-13: Consider making the port number configurable.

The port number is hard-coded. Consider making it configurable through environment variables for better flexibility.

+const PORT = process.env.PORT || 8515;
-}).listen(8515, () => {
+}).listen(PORT, () => {
-  console.log('Server is running on http://localhost:8515');
+  console.log(`Server is running on http://localhost:${PORT}`);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f08dd68 and f989c74.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (7)
  • examples/json-schema-complex-url/.meshrc.yml (1 hunks)
  • examples/json-schema-complex-url/assets/getData.json (1 hunks)
  • examples/json-schema-complex-url/package.json (1 hunks)
  • examples/json-schema-complex-url/sandbox.config.json (1 hunks)
  • examples/json-schema-complex-url/src/index.ts (1 hunks)
  • examples/json-schema-complex-url/tests/json-schema-complex-url.test.ts (1 hunks)
  • package.json (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • examples/json-schema-complex-url/sandbox.config.json
  • examples/json-schema-complex-url/assets/getData.json
  • examples/json-schema-complex-url/package.json
🧰 Additional context used
🪛 GitHub Check: CodeQL
examples/json-schema-complex-url/tests/json-schema-complex-url.test.ts

[failure] 40-40: Hard-coded credentials
The hard-coded value "Basic dXNlcm5hbWU6cGFzc3dvcmQ=" is used as authorization header.

⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: e2e / node v22
  • GitHub Check: e2e / node v18
  • GitHub Check: check
  • GitHub Check: integration / node 22
  • GitHub Check: unit / node 22
  • GitHub Check: integration / node 20
  • GitHub Check: apollo-federation-compatibility
  • GitHub Check: unit / node 20
  • GitHub Check: integration / node 18
  • GitHub Check: unit / node 18
  • GitHub Check: release / snapshot
  • GitHub Check: deployment
🔇 Additional comments (3)
examples/json-schema-complex-url/tests/json-schema-complex-url.test.ts (1)

5-46: Well-structured test implementation!

The test suite effectively:

  • Initializes and cleans up resources properly
  • Tests the complex URL handling with query parameters
  • Verifies the authorization header and URL construction
🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 40-40: Hard-coded credentials
The hard-coded value "Basic dXNlcm5hbWU6cGFzc3dvcmQ=" is used as authorization header.

examples/json-schema-complex-url/.meshrc.yml (1)

1-15: Well-structured Mesh configuration!

The configuration effectively:

  • Defines the JSON Schema handler
  • Configures the complex URL endpoint
  • Specifies the query operation with proper argument mapping
package.json (1)

39-39: LGTM!

The build script is correctly updated to include the new workspace.

Copy link
Contributor

github-actions bot commented Feb 18, 2025

💻 Website Preview

The latest changes are available as preview in: https://c831a395.graphql-mesh.pages.dev

@ardatan ardatan force-pushed the test-json-schema-hostname branch from f989c74 to b77842b Compare February 19, 2025 08:09
@ardatan ardatan merged commit 82a538b into master Feb 19, 2025
4 checks passed
@ardatan ardatan deleted the test-json-schema-hostname branch February 19, 2025 08:09
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