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

Aperta Adatta ai principianti
#405 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@RaphaelFakhri ci sta già lavorando.

Dal 5/11/2026.

  • #406 di @RaphaelFakhri — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, node.js

Direzione di ricerca

Leggi getValidMaxBatchSize e la convalida del costruttore nel codice sorgente di DataLoader; l’issue indica il confronto che fallisce e il controllo previsto. Trova i test esistenti per la convalida di maxBatchSize e aggiungi test per NaN. Il lavoro è completato quando la costruzione con NaN genera il TypeError previsto e i test correlati passano.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
JavaScript
Stelle
13.4k
Fork
522
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di graphql/dataloader

Tutte le issue di graphql/dataloader

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.