Skip to content

Commit f160b8c

Browse files
authoredFeb 14, 2025··
fix: Parse.Query.findAll not returning all objects with option json: true (#2449)
1 parent b69233f commit f160b8c

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed
 

‎integration/test/ParseQueryTest.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1493,13 +1493,17 @@ describe('Parse Query', () => {
14931493

14941494
it('can return all objects with findAll', async () => {
14951495
const objs = [...Array(101)].map(() => new Parse.Object('Container'));
1496-
14971496
await Parse.Object.saveAll(objs);
1498-
14991497
const query = new Parse.Query('Container');
1500-
15011498
const result = await query.findAll();
1499+
assert.equal(result.length, 101);
1500+
});
15021501

1502+
it('can return all objects with findAll json option', async () => {
1503+
const objs = [...Array(101)].map(() => new Parse.Object('Container'));
1504+
await Parse.Object.saveAll(objs);
1505+
const query = new Parse.Query('Container');
1506+
const result = await query.findAll({ json: true, batchSize: 100 });
15031507
assert.equal(result.length, 101);
15041508
});
15051509

‎src/ParseQuery.ts

+8-27
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ class ParseQuery {
721721
* be used for this request.
722722
* <li>sessionToken: A valid session token, used for making a request on
723723
* behalf of a specific user.
724+
* <li>json: Return raw JSON without converting to Parse.Object.
724725
* </ul>
725726
* @returns {Promise} A promise that is resolved with the results when
726727
* the query completes.
@@ -924,33 +925,9 @@ class ParseQuery {
924925
return Promise.reject(error);
925926
}
926927

927-
const query = new ParseQuery(this.className);
928-
query._limit = options.batchSize || 100;
929-
query._include = [...this._include];
930-
query._exclude = [...this._exclude];
931-
if (this._select) {
932-
query._select = [...this._select];
933-
}
934-
query._hint = this._hint;
935-
query._where = {};
936-
for (const attr in this._where) {
937-
const val = this._where[attr];
938-
if (Array.isArray(val)) {
939-
query._where[attr] = val.map(v => {
940-
return v;
941-
});
942-
} else if (val && typeof val === 'object') {
943-
const conditionMap = {};
944-
query._where[attr] = conditionMap;
945-
for (const cond in val) {
946-
conditionMap[cond] = val[cond];
947-
}
948-
} else {
949-
query._where[attr] = val;
950-
}
951-
}
952-
928+
const query = ParseQuery.fromJSON(this.className, this.toJSON());
953929
query.ascending('objectId');
930+
query._limit = options.batchSize || 100;
954931

955932
const findOptions = ParseObject._getRequestOptions(options);
956933
let finished = false;
@@ -965,7 +942,11 @@ class ParseQuery {
965942
Promise.resolve(previousResults.length > 0 && callback(previousResults)),
966943
]);
967944
if (results.length >= query._limit) {
968-
query.greaterThan('objectId', results[results.length - 1].id);
945+
if (findOptions.json) {
946+
query.greaterThan('objectId', (results[results.length - 1] as any).objectId);
947+
} else {
948+
query.greaterThan('objectId', results[results.length - 1].id);
949+
}
969950
previousResults = results;
970951
} else if (results.length > 0) {
971952
await Promise.resolve(callback(results));

‎src/__tests__/ParseQuery-test.js

+13
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,7 @@ describe('ParseQuery', () => {
18421842
useMasterKey: true,
18431843
sessionToken: '1234',
18441844
batchSize: 50,
1845+
json: true,
18451846
};
18461847
const q = new ParseQuery('Item');
18471848
await q.findAll(batchOptions);
@@ -1855,6 +1856,7 @@ describe('ParseQuery', () => {
18551856
});
18561857
expect(options.useMasterKey).toBe(true);
18571858
expect(options.sessionToken).toEqual('1234');
1859+
expect(options.json).toEqual(true);
18581860
});
18591861

18601862
it('only makes one request when the results fit in one page', async () => {
@@ -1874,6 +1876,17 @@ describe('ParseQuery', () => {
18741876
const results = await q.findAll();
18751877
expect(results.map(obj => obj.attributes.size)).toEqual(['medium', 'small']);
18761878
});
1879+
1880+
it('Returns all objects with json', async () => {
1881+
const q = new ParseQuery('Item');
1882+
const results = await q.findAll({ json: true, batchSize: 2 });
1883+
expect(results.length).toEqual(3);
1884+
expect(findMock).toHaveBeenCalledTimes(2);
1885+
results.map(result => {
1886+
expect(result.id).toBeUndefined();
1887+
expect(result.objectId).toBeDefined();
1888+
});
1889+
});
18771890
});
18781891

18791892
it('can iterate over results with each()', done => {

0 commit comments

Comments
 (0)
Please sign in to comment.