@@ -20,6 +20,7 @@ export type BatchMiddlewareOpts = {|
20
20
| ( ( requestList : RequestWrapper [ ] ) => string | Promise < string > ) ,
21
21
batchTimeout ? : number ,
22
22
maxBatchSize ? : number ,
23
+ maxRequestsPerBatch ? : number ,
23
24
allowMutations ? : boolean ,
24
25
method ? : 'POST' | 'GET' ,
25
26
headers ?: Headers | Promise < Headers > | ( ( req : RelayRequestBatch ) => Headers | Promise < Headers > ) ,
@@ -57,6 +58,7 @@ export default function batchMiddleware(options?: BatchMiddlewareOpts): Middlewa
57
58
const allowMutations = opts . allowMutations || false ;
58
59
const batchUrl = opts . batchUrl || '/graphql/batch' ;
59
60
const maxBatchSize = opts . maxBatchSize || DEFAULT_BATCH_SIZE ;
61
+ const maxRequestsPerBatch = opts . maxRequestsPerBatch || 0 ; // 0 is the same as no limit
60
62
const singleton = { } ;
61
63
62
64
const fetchOpts = { } ;
@@ -94,6 +96,7 @@ export default function batchMiddleware(options?: BatchMiddlewareOpts): Middlewa
94
96
batchUrl,
95
97
singleton,
96
98
maxBatchSize,
99
+ maxRequestsPerBatch,
97
100
fetchOpts,
98
101
} ) ;
99
102
} ;
@@ -111,6 +114,13 @@ function passThroughBatch(req: RelayRequest, next, opts) {
111
114
singleton . batcher = prepareNewBatcher ( next , opts ) ;
112
115
}
113
116
117
+ if (
118
+ opts . maxRequestsPerBatch &&
119
+ singleton . batcher . requestList . length + 1 > opts . maxRequestsPerBatch
120
+ ) {
121
+ singleton . batcher = prepareNewBatcher ( next , opts ) ;
122
+ }
123
+
114
124
if ( singleton . batcher . bodySize + bodyLength + 1 > opts . maxBatchSize ) {
115
125
singleton . batcher = prepareNewBatcher ( next , opts ) ;
116
126
}
0 commit comments