@@ -5,7 +5,7 @@ import { isFunction } from '../utils';
55import RelayRequestBatch from '../RelayRequestBatch' ;
66import RelayRequest from '../RelayRequest' ;
77import type RelayResponse from '../RelayResponse' ;
8- import type { Middleware , FetchOpts } from '../definition' ;
8+ import type { Middleware , FetchOpts , ConcreteBatch } from '../definition' ;
99import RRNLError from '../RRNLError' ;
1010
1111// Max out at roughly 100kb (express-graphql imposed max)
@@ -21,6 +21,7 @@ export type BatchMiddlewareOpts = {|
2121 batchTimeout ? : number ,
2222 maxBatchSize ? : number ,
2323 allowMutations ? : boolean ,
24+ allowOperation ?: ( operation : ConcreteBatch ) => boolean ,
2425 method ?: 'POST' | 'GET' ,
2526 headers ?: Headers | Promise < Headers > | ( ( req : RelayRequestBatch ) => Headers | Promise < Headers > ) ,
2627 // Avaliable request modes in fetch options. For details see https://fetch.spec.whatwg.org/#requests
@@ -57,6 +58,7 @@ export default function batchMiddleware(options?: BatchMiddlewareOpts): Middlewa
5758 const allowMutations = opts . allowMutations || false ;
5859 const batchUrl = opts . batchUrl || '/graphql/batch' ;
5960 const maxBatchSize = opts . maxBatchSize || DEFAULT_BATCH_SIZE ;
61+ const allowOperation = opts . allowOperation || true ;
6062 const singleton = { } ;
6163
6264 const fetchOpts = { } ;
@@ -79,6 +81,10 @@ export default function batchMiddleware(options?: BatchMiddlewareOpts): Middlewa
7981 ) ;
8082 }
8183
84+ if ( isFunction ( opts . allowOperation ) && ! opts . allowOperation ( req . operation ) ) {
85+ return next ( req ) ;
86+ }
87+
8288 // req with FormData can not be batched
8389 if ( req . isFormData ( ) ) {
8490 return next ( req ) ;
@@ -94,6 +100,7 @@ export default function batchMiddleware(options?: BatchMiddlewareOpts): Middlewa
94100 batchUrl,
95101 singleton,
96102 maxBatchSize,
103+ allowOperation,
97104 fetchOpts,
98105 } ) ;
99106 } ;
0 commit comments