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(executor-graphql-ws): respect the given lazy and lazyCloseTimeout options #591

Merged
merged 6 commits into from
Feb 4, 2025

Conversation

ardatan
Copy link
Member

@ardatan ardatan commented Feb 4, 2025

Fixes the regression introduced in #481

@ardatan ardatan requested a review from enisdenjo February 4, 2025 13:17
Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue that prevented custom configuration of lazy connection options.
  • New Features
    • Enabled support for custom event listeners during WebSocket connections.
  • Refactor
    • Streamlined the client instantiation process and improved connection parameter handling.
  • Chores
    • Removed an unnecessary external dependency to simplify maintenance.

Walkthrough

The changes address a regression in the @graphql-tools/executor-graphql-ws package that previously prevented custom configuration of the lazy and lazyCloseTimeout options. The pull request updates the GraphQLWSExecutorOptions interface and the buildGraphQLWSExecutor function by refining the print property, encapsulating client creation options, and setting defaults for connection parameters. Additionally, type imports have been added for improved type safety. A similar patch is introduced for the @graphql-mesh/transport-ws package to optimize Client instantiation.

Changes

File Change Summary
.changeset/twenty-brooms-rush.md Introduces a patch to restore the ability to pass custom lazy and lazyCloseTimeout options in the GraphQL WS executor package.
packages/executors/graphql-ws/src/index.ts Updates the GraphQLWSExecutorOptions interface by changing the print property to a function signature. Refactors the buildGraphQLWSExecutor function to encapsulate client options (using defaults for lazy and lazyCloseTimeout), and adds type imports for DocumentNode and ClientOptions to enhance type safety.
.changeset/twelve-ghosts-smoke.md Introduces a patch to optimize Client instantiation within the @graphql-mesh/transport-ws package by utilizing an existing Client instance instead of creating a new one.
packages/transports/ws/src/index.ts Modifies the getSubgraphExecutor method by removing the buildExecutor parameter and replacing it with an optional onClient callback. Refactors the WebSocket client construction and retains event handlers as part of the new executor configuration.
packages/transports/ws/tests/ws.spec.ts Updates the createTServer function to replace the buildExecutor parameter with onClient, reflecting changes in client connection handling. Adjusts test cases to align with the new logic and removes references to buildGraphQLWSExecutor.
.changeset/@graphql-mesh_transport-ws-591-dependencies.md Removes the isomorphic-ws dependency from the @graphql-mesh/transport-ws package, streamlining dependency management.
packages/transports/ws/package.json Modifies the dependencies section to remove the isomorphic-ws dependency from the @graphql-mesh/transport-ws package.

Possibly related PRs

  • Upgrade to graphql-ws v6 and release v1 of WebSocket transport #481: The changes in the main PR, which involve modifications to the GraphQLWSExecutorOptions interface and the buildGraphQLWSExecutor function, are related to the updates in the retrieved PR that also focus on the @graphql-tools/executor-graphql-ws package and its handling of WebSocket client options.
  • Upcoming Release Changes #583: The changes in the main PR are related to modifications in the GraphQLWSExecutorOptions interface and the buildGraphQLWSExecutor function, which are also referenced in the retrieved PR that discusses updates to the @graphql-tools/executor-graphql-ws package, including the removal of dependency on types for executor options and an upgrade of graphql-ws.

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 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 2ca260f and 428d839.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • .changeset/@graphql-mesh_transport-ws-591-dependencies.md (1 hunks)
  • packages/transports/ws/package.json (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/transports/ws/package.json
✅ Files skipped from review due to trivial changes (1)
  • .changeset/@graphql-mesh_transport-ws-591-dependencies.md
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Binary built on windows-latest
  • GitHub Check: Binary built on macos-13
  • GitHub Check: E2E / Node Binary on Windows
  • GitHub Check: Leaks / Node v20

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

@theguild-bot
Copy link
Collaborator

theguild-bot commented Feb 4, 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-tools/executor-graphql-ws 2.0.1-alpha-428d839c1f4eef2b452ff9e7dc9a82dcc5e8d0fd npm ↗︎ unpkg ↗︎
@graphql-hive/gateway 1.9.3-alpha-428d839c1f4eef2b452ff9e7dc9a82dcc5e8d0fd npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-ws 1.0.1-alpha-428d839c1f4eef2b452ff9e7dc9a82dcc5e8d0fd 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: 0

🧹 Nitpick comments (2)
packages/executors/graphql-ws/src/index.ts (1)

76-81: Simplify the boolean logic for the lazy option.

The ternary operator for the lazy option can be simplified.

Apply this diff to simplify the boolean logic:

-      lazy: clientOptionsOrClient.lazy === false ? false : true,
+      lazy: clientOptionsOrClient.lazy !== false,
🧰 Tools
🪛 Biome (1.9.4)

[error] 79-79: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

.changeset/twenty-brooms-rush.md (1)

1-6: Improve the grammar in the changeset description.

The description has minor grammatical issues.

Apply this diff to improve the grammar:

-Fix the regression preventing user to pass custom `lazy` and `lazyCloseTimeout` options
+Fix the regression preventing users from passing custom `lazy` and `lazyCloseTimeout` options
🧰 Tools
🪛 LanguageTool

[uncategorized] ~5-~5: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...atch --- Fix the regression preventing user to pass custom lazy and `lazyCloseTim...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)


[uncategorized] ~5-~5: This verb may not be in the correct form. Consider using a different form for this context.
Context: ... Fix the regression preventing user to pass custom lazy and lazyCloseTimeout op...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a2b6fe9 and 5287411.

📒 Files selected for processing (2)
  • .changeset/twenty-brooms-rush.md (1 hunks)
  • packages/executors/graphql-ws/src/index.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
packages/executors/graphql-ws/src/index.ts (2)

Pattern packages/**: In this directory we keep all packages relevant to the gateway.

In most cases, when changes are made to the source code / dependencies in these directories, we also require to have a corresponding changeset file, created using yarn changeset with a full description on the changes with an example.
Also, when new features are added the packages, the changeset file should mention minor semver change. When a bug is fixed, patch needs to be used. The major bump is used for a PR that has breaking changes.


Pattern **: For all PRs, we would like to verify that a Linear issue is linked. Check if there's a mention for "GW-*" in the PR description, and the us know when it's missing.

In most cases, when a PR adds a new functionality, we would like to make sure it has documentation in the corresponding console project.
Use the global knowledge feature to search for PRs in graphql-hive/console repository that adds documentation. Suggest to create a follow up issue to add the missing documentation.

🪛 LanguageTool
.changeset/twenty-brooms-rush.md

[uncategorized] ~5-~5: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...atch --- Fix the regression preventing user to pass custom lazy and `lazyCloseTim...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)


[uncategorized] ~5-~5: This verb may not be in the correct form. Consider using a different form for this context.
Context: ... Fix the regression preventing user to pass custom lazy and lazyCloseTimeout op...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)

🪛 Biome (1.9.4)
packages/executors/graphql-ws/src/index.ts

[error] 79-79: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

⏰ Context from checks skipped due to timeout of 90000ms (44)
  • GitHub Check: Examples / Convert operation-field-permissions
  • GitHub Check: Examples / Convert type-merging-batching
  • GitHub Check: Examples / Convert subscriptions-with-transforms
  • GitHub Check: Examples / Convert programmatic-batching
  • GitHub Check: Examples / Convert openapi-subscriptions
  • GitHub Check: Examples / Convert openapi-javascript-wiki
  • GitHub Check: Examples / Convert openapi-arg-rename
  • GitHub Check: Examples / Convert openapi-additional-resolvers
  • GitHub Check: Examples / Convert json-schema-subscriptions
  • GitHub Check: Examples / Convert interface-additional-resolvers
  • GitHub Check: Examples / Convert hmac-auth-https
  • GitHub Check: Examples / Convert federation-subscriptions-passthrough
  • GitHub Check: Examples / Convert apq-subgraphs
  • GitHub Check: Examples / Convert file-upload
  • GitHub Check: Examples / Convert federation-mixed
  • GitHub Check: Examples / Convert federation-example
  • GitHub Check: Examples / Convert extra-fields
  • GitHub Check: Binary built on ubuntu-24.04-arm
  • GitHub Check: Binary built on windows-latest
  • GitHub Check: Binary built on macos-14
  • GitHub Check: Bun Docker image
  • GitHub Check: Binary built on macos-13
  • GitHub Check: Node Docker image
  • GitHub Check: Binary built on ubuntu-latest
  • GitHub Check: E2E / Bun Docker on Ubuntu
  • GitHub Check: E2E / Bun on Ubuntu
  • GitHub Check: E2E / Node Binary on Windows
  • GitHub Check: E2E / Node Binary on Ubuntu
  • GitHub Check: E2E / Node Docker on Ubuntu
  • GitHub Check: Bundle
  • GitHub Check: Benchmark / bun / 1000 items
  • GitHub Check: E2E / Node 22 on Ubuntu
  • GitHub Check: E2E / Node 20 on Ubuntu
  • GitHub Check: Build
  • GitHub Check: Benchmark / bun / 100 items
  • GitHub Check: Benchmark / bun / 10 items
  • GitHub Check: E2E / Node 18 on Ubuntu
  • GitHub Check: Benchmark / node / 1000 items
  • GitHub Check: Leaks / Node v22
  • GitHub Check: Benchmark / node / 100 items
  • GitHub Check: Benchmark / node / 10 items
  • GitHub Check: Leaks / Node v20
  • GitHub Check: Unit / Bun
  • GitHub Check: Leaks / Node v18
🔇 Additional comments (3)
packages/executors/graphql-ws/src/index.ts (3)

12-13: LGTM!

The added type imports enhance type safety and properly support the refactored code.


18-18: LGTM!

The explicit function signature for the print property improves type clarity and better documents the expected behavior.


88-89: LGTM!

The client creation is properly encapsulated with the refactored options.

@theguild-bot
Copy link
Collaborator

theguild-bot commented Feb 4, 2025

🚀 Snapshot Release (Binary for macOS-ARM64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Feb 4, 2025

🚀 Snapshot Release (Binary for Linux-ARM64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Feb 4, 2025

🚀 Snapshot Release (Binary for Linux-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Feb 4, 2025

🚀 Snapshot Release (Node Docker Image)

The latest changes of this PR are available as image on GitHub Container Registry (based on the declared changesets):

ghcr.io/graphql-hive/gateway:1.9.3-alpha-428d839c1f4eef2b452ff9e7dc9a82dcc5e8d0fd

@theguild-bot
Copy link
Collaborator

theguild-bot commented Feb 4, 2025

🚀 Snapshot Release (Bun Docker Image)

The latest changes of this PR are available as image on GitHub Container Registry (based on the declared changesets):

ghcr.io/graphql-hive/gateway:1.9.3-alpha-428d839c1f4eef2b452ff9e7dc9a82dcc5e8d0fd-bun

@theguild-bot
Copy link
Collaborator

theguild-bot commented Feb 4, 2025

🚀 Snapshot Release (Binary for Windows-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Feb 4, 2025

🚀 Snapshot Release (Binary for macOS-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

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

🧹 Nitpick comments (1)
.changeset/twelve-ghosts-smoke.md (1)

1-6: Enhance the changeset description.

While the current description explains the optimization, it would be helpful to mention that this fixes a regression where lazy and lazyCloseTimeout options were not being respected.

---
'@graphql-mesh/transport-ws': patch
---

-Avoid having an extra Client instantiation in the transport, and use the one in the executor
+Fix regression where `lazy` and `lazyCloseTimeout` options were not being respected. This change also optimizes Client instantiation by reusing the executor's Client instance instead of creating an additional one in the transport layer.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5287411 and 2ca260f.

📒 Files selected for processing (5)
  • .changeset/twelve-ghosts-smoke.md (1 hunks)
  • .changeset/twenty-brooms-rush.md (1 hunks)
  • packages/executors/graphql-ws/src/index.ts (3 hunks)
  • packages/transports/ws/src/index.ts (3 hunks)
  • packages/transports/ws/tests/ws.spec.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/twenty-brooms-rush.md
🧰 Additional context used
📓 Path-based instructions (3)
packages/transports/ws/src/index.ts (3)

Pattern packages/**: In this directory we keep all packages relevant to the gateway.

In most cases, when changes are made to the source code / dependencies in these directories, we also require to have a corresponding changeset file, created using yarn changeset with a full description on the changes with an example.
Also, when new features are added the packages, the changeset file should mention minor semver change. When a bug is fixed, patch needs to be used. The major bump is used for a PR that has breaking changes.


Pattern packages/transports/**: The transports configures how to deal with HTTP requests that are made from the GraphQL gateway to the GraphQL subgraphs. Transports manipulates the HTTP calls, headers, protocols and others.


Pattern **: For all PRs, we would like to verify that a Linear issue is linked. Check if there's a mention for "GW-*" in the PR description, and the us know when it's missing.

In most cases, when a PR adds a new functionality, we would like to make sure it has documentation in the corresponding console project.
Use the global knowledge feature to search for PRs in graphql-hive/console repository that adds documentation. Suggest to create a follow up issue to add the missing documentation.

packages/executors/graphql-ws/src/index.ts (2)

Pattern packages/**: In this directory we keep all packages relevant to the gateway.

In most cases, when changes are made to the source code / dependencies in these directories, we also require to have a corresponding changeset file, created using yarn changeset with a full description on the changes with an example.
Also, when new features are added the packages, the changeset file should mention minor semver change. When a bug is fixed, patch needs to be used. The major bump is used for a PR that has breaking changes.


Pattern **: For all PRs, we would like to verify that a Linear issue is linked. Check if there's a mention for "GW-*" in the PR description, and the us know when it's missing.

In most cases, when a PR adds a new functionality, we would like to make sure it has documentation in the corresponding console project.
Use the global knowledge feature to search for PRs in graphql-hive/console repository that adds documentation. Suggest to create a follow up issue to add the missing documentation.

packages/transports/ws/tests/ws.spec.ts (3)

Pattern packages/**: In this directory we keep all packages relevant to the gateway.

In most cases, when changes are made to the source code / dependencies in these directories, we also require to have a corresponding changeset file, created using yarn changeset with a full description on the changes with an example.
Also, when new features are added the packages, the changeset file should mention minor semver change. When a bug is fixed, patch needs to be used. The major bump is used for a PR that has breaking changes.


Pattern packages/transports/**: The transports configures how to deal with HTTP requests that are made from the GraphQL gateway to the GraphQL subgraphs. Transports manipulates the HTTP calls, headers, protocols and others.


Pattern **: For all PRs, we would like to verify that a Linear issue is linked. Check if there's a mention for "GW-*" in the PR description, and the us know when it's missing.

In most cases, when a PR adds a new functionality, we would like to make sure it has documentation in the corresponding console project.
Use the global knowledge feature to search for PRs in graphql-hive/console repository that adds documentation. Suggest to create a follow up issue to add the missing documentation.

⏰ Context from checks skipped due to timeout of 90000ms (29)
  • GitHub Check: Binary built on ubuntu-24.04-arm
  • GitHub Check: Binary built on windows-latest
  • GitHub Check: Bun Docker image
  • GitHub Check: Binary built on macos-14
  • GitHub Check: Node Docker image
  • GitHub Check: Binary built on macos-13
  • GitHub Check: Binary built on ubuntu-latest
  • GitHub Check: E2E / Bun Docker on Ubuntu
  • GitHub Check: E2E / Bun on Ubuntu
  • GitHub Check: E2E / Node Binary on Windows
  • GitHub Check: E2E / Node Binary on Ubuntu
  • GitHub Check: Unit / Bun
  • GitHub Check: E2E / Node Docker on Ubuntu
  • GitHub Check: E2E / Node 22 on Ubuntu
  • GitHub Check: Leaks / Node v22
  • GitHub Check: Benchmark / bun / 1000 items
  • GitHub Check: Benchmark / bun / 100 items
  • GitHub Check: Leaks / Node v20
  • GitHub Check: Benchmark / bun / 10 items
  • GitHub Check: E2E / Node 20 on Ubuntu
  • GitHub Check: Benchmark / node / 1000 items
  • GitHub Check: Unit / Node v18
  • GitHub Check: Benchmark / node / 100 items
  • GitHub Check: Leaks / Node v18
  • GitHub Check: Bundle
  • GitHub Check: Benchmark / node / 10 items
  • GitHub Check: E2E / Node 18 on Ubuntu
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Build
🔇 Additional comments (7)
packages/transports/ws/src/index.ts (3)

37-41: LGTM! Well-documented internal API.

The onClient parameter is properly documented with @internal JSDoc comment to indicate it's not part of the public API.


80-116: LGTM! Comprehensive WebSocket lifecycle logging.

The implementation properly handles all WebSocket lifecycle events with detailed logging, and the closed event correctly cleans up the executor map to prevent memory leaks.


83-85: Verify default values for lazy options.

The code sets default values for lazy: true and lazyCloseTimeout: 3_000. These values should be documented in the README to help users understand the default behavior.

packages/executors/graphql-ws/src/index.ts (3)

28-28: LGTM! Improved type safety.

The print function type is now properly defined with explicit parameter and return types.


59-80: LGTM! Well-documented internal APIs.

The on and onClient options are properly documented with @internal JSDoc comments.


112-113: LGTM! Fixed regression with lazy options.

The code now properly respects the lazy and lazyCloseTimeout options:

  • lazy defaults to true unless explicitly set to false
  • lazyCloseTimeout defaults to 0 if not provided
packages/transports/ws/tests/ws.spec.ts (1)

224-231: LGTM! Comprehensive WebSocket lifecycle testing.

The test properly validates WebSocket lifecycle events using the new onClient callback.

@ardatan ardatan requested a review from enisdenjo February 4, 2025 13:44
@ardatan ardatan merged commit 7d42160 into main Feb 4, 2025
60 checks passed
@ardatan ardatan deleted the pass-missing-params branch February 4, 2025 14:25
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.

3 participants