[BUG] `maxBatchSize: NaN` is accepted and silently disables batching

オープン 初心者向け
#405 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@RaphaelFakhri がすでに取り組んでいます。

2026年11月5日 から。

  • #406 @RaphaelFakhri による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js

調査の方向性

DataLoader のソース内にある getValidMaxBatchSize とコンストラクターの検証を読みます。issue には、失敗する比較と意図されたチェックが示されています。maxBatchSize の検証に関する既存のテストを見つけ、NaN のテストを追加します。NaN を指定して構築すると期待される TypeError がスローされ、関連するテストがパスすれば完了です。

索引モデルが issue の本文から書いたものです。

説明

new DataLoader(fn, { maxBatchSize: NaN }) throws TypeError: maxBatchSize must be a positive number: NaN, the same as it does for 0, negative numbers, and non-numbers.

Current Behavior

The constructor accepts NaN. getCurrentBatch then compares keys.length < NaN, which is always false, so every load() call starts a new batch. Batching is turned off without any error or warning.

Possible Solution

In getValidMaxBatchSize, replace maxBatchSize < 1 with !(maxBatchSize >= 1) so that NaN fails the check.

Steps to Reproduce

const DataLoader = require('dataloader');

const calls = [];
const loader = new DataLoader(
  async keys => {
    calls.push(keys);
    return keys;
  },
  // For example, read from an environment variable that is not set.
  { maxBatchSize: Number(process.env.MAX_BATCH_SIZE) },
);

Promise.all([loader.load(1), loader.load(2), loader.load(3)]).then(() =>
  console.log(JSON.stringify(calls)),
);
// Prints [[1],[2],[3]]. Expected a TypeError from the constructor.

Context

maxBatchSize often comes from configuration, for example Number(process.env.X) or parseInt(value, 10). Both return NaN when the value is missing or invalid. The loader keeps working, but it sends one request per key, and nothing points to the misconfiguration.

主要言語
JavaScript
スター
13.4k
フォーク
522
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

graphql/dataloader のほかの issue

graphql/dataloader の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。