Skip to content

fix(batch-execute/signal): handle batched execution cancellation - #1928

Open
ardatan wants to merge 15 commits into
mainfrom
batch-execution-cancellation
Open

fix(batch-execute/signal): handle batched execution cancellation#1928
ardatan wants to merge 15 commits into
mainfrom
batch-execution-cancellation

Conversation

@ardatan

@ardatan ardatan commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

New utility abortSignalAll

We have introduced a new utility function abortSignalAll that allows you to combine multiple AbortSignal instances into a single signal. So, if all of the individual signals are aborted, the combined signal will also be aborted. This is particularly useful in scenarios such as batched GraphQL requests, where you may want to abort the entire batch if all individual requests are aborted.

import { abortSignalAll } from '@graphql-hive/signal';
const ctrl1 = new AbortController();
const ctrl2 = new AbortController();

const combinedSignal = abortSignalAll([ctrl1.signal, ctrl2.signal]);

// Aborting both individual signals will abort the combined signal
ctrl1.abort();

console.assert(!combinedSignal.aborted); // still not aborted

ctrl2.abort();
console.assert(combinedSignal.aborted); // now aborted

Execution cancellation on batched requests

When using Batched Execution, it is now possible to cancel the entire batched request if all individual requests' AbortSignals are aborted. This enhancement improves resource management and responsiveness in applications that utilize batched GraphQL operations.

Previously, aborting individual requests did not affect the batched request. With this update, if all individual requests signal an abort, the batched request will also be aborted, ensuring that unnecessary processing is avoided.

This feature is implemented using the new utility function abortSignalAll, which combines multiple AbortSignal instances into a single signal. If all of the requests are aborted, the combined signal will also be aborted.

@ardatan
ardatan force-pushed the batch-execution-cancellation branch from 4f3afb4 to 51263c0 Compare February 4, 2026 15:23
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ardatan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves resource management for GraphQL batched requests by introducing a new AbortSignal.all utility. This utility allows for the creation of a composite AbortSignal that triggers only when every individual signal it monitors has been aborted. This new capability is then integrated into the batched execution mechanism, enabling the entire batched operation to be cancelled efficiently and automatically once all its constituent requests are no longer needed, preventing unnecessary processing.

Highlights

  • New AbortSignal.all Utility: Introduced a new function to create a combined AbortSignal that only aborts when all its constituent signals have aborted.
  • Batched Execution Cancellation: Enhanced GraphQL batched execution to support cancellation of the entire batch if all individual requests within it are aborted.
Changelog
  • .changeset/fair-radios-juggle.md
    • Added a new utility function AbortSignal.all to combine multiple AbortSignal instances, which aborts only when all individual signals are aborted.
  • .changeset/rare-snakes-prove.md
    • Enabled cancellation of batched GraphQL requests when all individual request AbortSignals are aborted, improving resource management.
  • packages/batch-execute/src/mergeRequests.ts
    • Imported abortSignalAll and integrated it to create a combined AbortSignal for batched requests, ensuring the merged request's signal reflects the state of all individual request signals.
  • packages/batch-execute/tests/batchExecute.test.ts
    • Updated executor signature to include signal and added new test cases to validate batched request cancellation logic: ensuring no abort if only some signals abort, and proper abort if all signals abort.
  • packages/signal/src/abortSignalAll.ts
    • Implemented the abortSignalAll function, providing a memory-safe way to create a composite AbortSignal that only aborts when all provided signals have aborted, including handling edge cases for zero or one input signals.
  • packages/signal/src/abortSignalAny.ts
    • Refactored the abortSignalAny ponyfill to leverage shared utility functions (isNode, signalRegistry) from utils.ts, centralizing common logic and improving maintainability.
  • packages/signal/src/utils.ts
    • Created a new utility file to consolidate common definitions like isNode, controllerInSignalSy, and signalRegistry, promoting code reuse and consistency across signal-related functionalities.
  • packages/signal/tests/abortSignalAll.test.ts
    • Added comprehensive unit tests for abortSignalAll, covering its core functionality, edge cases, and crucial memory leak detection to ensure proper resource cleanup.
Activity
  • The author ardatan initiated this pull request to address batched execution cancellation.
  • A new utility AbortSignal.all was developed in the @graphql-hive/signal package.
  • This new utility was then integrated into the @graphql-tools/batch-execute package to enable the desired cancellation behavior.
  • Extensive tests, including memory leak checks, were added for the new abortSignalAll function.
  • Existing abortSignalAny utility was refactored to use shared internal utilities.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new AbortSignal.all utility and integrates it into batched executions to allow for cancellation when all individual requests are aborted. The implementation is thoughtful, especially regarding memory management with WeakRef and FinalizationRegistry. My review focuses on a couple of documentation inconsistencies in the changeset files and a potential performance improvement in the new abortSignalAll function.

Comment thread .changeset/fair-radios-juggle.md Outdated
Comment thread .changeset/rare-snakes-prove.md Outdated
Comment thread packages/signal/src/abortSignalAll.ts
@ardatan
ardatan marked this pull request as draft February 4, 2026 15:28
@theguild-bot

theguild-bot commented Feb 4, 2026

Copy link
Copy Markdown
Collaborator

🚀 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/batch-delegate 10.0.18-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-tools/batch-execute 10.1.0-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-tools/delegate 12.0.12-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-tools/executor-http 3.1.2-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-tools/federation 4.3.1-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-mesh/fusion-runtime 1.8.1-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-hive/gateway 2.5.10-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-hive/nestjs 2.0.51-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-hive/plugin-aws-sigv4 2.0.33-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-hive/plugin-opentelemetry 1.4.7-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-prometheus 2.1.26-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-hive/router-runtime 1.2.1-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-hive/gateway-runtime 2.7.8-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-hive/signal 2.1.0-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-tools/stitch 10.1.16-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-tools/stitching-directives 4.0.18-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-hive/gateway-testing 6.0.8-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-common 1.0.16-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-http 1.0.17-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-http-callback 1.0.17-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-ws 2.0.17-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎
@graphql-tools/wrap 11.1.12-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379 npm ↗︎ unpkg ↗︎

@ardatan
ardatan force-pushed the batch-execution-cancellation branch from e0aaaf4 to 1f7e943 Compare February 4, 2026 15:53
@ardatan
ardatan force-pushed the batch-execution-cancellation branch 2 times, most recently from 2dbb76f to 198e6bc Compare February 20, 2026 01:55
@ardatan
ardatan marked this pull request as ready for review February 20, 2026 16:41
@ardatan
ardatan requested a review from enisdenjo February 20, 2026 16:41
@ardatan
ardatan enabled auto-merge (squash) February 20, 2026 16:41
@ardatan
ardatan force-pushed the batch-execution-cancellation branch 2 times, most recently from 85ef635 to 089f88e Compare February 23, 2026 11:17
ardatan and others added 8 commits February 23, 2026 08:36
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@ardatan
ardatan force-pushed the batch-execution-cancellation branch from 089f88e to 396d536 Compare February 23, 2026 13:36
@ardatan
ardatan disabled auto-merge March 10, 2026 09:22
@theguild-bot

theguild-bot commented Mar 11, 2026

Copy link
Copy Markdown
Collaborator

🚀 Snapshot Release (Binary for Linux-ARM64)

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

Download

@theguild-bot

theguild-bot commented Mar 11, 2026

Copy link
Copy Markdown
Collaborator

🚀 Snapshot Release (Binary for Linux-X64)

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

Download

@theguild-bot

theguild-bot commented Mar 11, 2026

Copy link
Copy Markdown
Collaborator

🚀 Snapshot Release (Binary for macOS-ARM64)

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

Download

@theguild-bot

theguild-bot commented Mar 11, 2026

Copy link
Copy Markdown
Collaborator

🚀 Snapshot Release (Binary for macOS-X64)

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

Download

@theguild-bot

theguild-bot commented Mar 11, 2026

Copy link
Copy Markdown
Collaborator

🚀 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:2.5.10-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379-bun

@theguild-bot

theguild-bot commented Mar 11, 2026

Copy link
Copy Markdown
Collaborator

🚀 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:2.5.10-alpha-a9d40d9a3f2c4a1c7a7b1203779f9276711a2379

@theguild-bot

theguild-bot commented Mar 11, 2026

Copy link
Copy Markdown
Collaborator

🚀 Snapshot Release (Binary for Windows-X64)

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

Download

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