Skip to content

Commit 3ccf314

Browse files
authored
fix: convert to batch API when URI might be too long (#422)
1 parent 9871dae commit 3ccf314

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/request.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,16 @@ const AVRequest = (route, className, objectId, method, dataObject = {}, authOpti
321321
}
322322
return getServerURLPromise.then(() => {
323323
const apiURL = createApiUrl(route, className, objectId, method, dataObject);
324+
// prevent URI too long
325+
if (apiURL.length > 2000 && method.toLowerCase() === 'get') {
326+
const body = {
327+
request: {
328+
method,
329+
path: apiURL,
330+
},
331+
};
332+
return AVRequest('batch', null, null, 'POST', body, authOptions);
333+
}
324334
return setHeaders(authOptions).then(
325335
headers => ajax(method, apiURL, dataObject, headers)
326336
.then(

test/query.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ describe('Queries', function () {
194194
expect(gameScore.get('test').get('foo')).to.be('bar');
195195
});
196196
});
197+
198+
it('containsAll with an large array should not cause URI too long', () => {
199+
return new AV.Query(GameScore)
200+
.containsAll('test', new Array(1000).fill('5821abe62e958a00540046d5'))
201+
.find();
202+
});
197203
});
198204

199205
describe('Query with different condtions', function () {

0 commit comments

Comments
 (0)