Skip to content

feat: add json option to Parse.Query.each() #1539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions integration/test/ParseQueryTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ describe('Parse Query', () => {
assert.strictEqual(result.foo, 'bar');
assert.strictEqual(result.className, 'TestObject');
assert.strictEqual(result.objectId, object.id);

await query.each((obj) => {
assert.strictEqual(obj instanceof Parse.Object, false);
assert.strictEqual(obj.foo, 'bar');
assert.strictEqual(obj.className, 'TestObject');
assert.strictEqual(obj.objectId, object.id);
}, { json: true });
});

it('can do query with count', async () => {
Expand Down
4 changes: 4 additions & 0 deletions src/ParseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,9 @@ class ParseQuery {
if (options.hasOwnProperty('context') && typeof options.context === 'object') {
findOptions.context = options.context;
}
if (options.hasOwnProperty('json')) {
findOptions.json = options.json;
}

let finished = false;
let previousResults = [];
Expand Down Expand Up @@ -1030,6 +1033,7 @@ class ParseQuery {
* be used for this request.
* <li>sessionToken: A valid session token, used for making a request on
* behalf of a specific user.
* <li>json: Return raw json without converting to Parse.Object
* </ul>
* @returns {Promise} A promise that will be fulfilled once the
* iteration has completed.
Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/ParseQuery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,13 @@ describe('ParseQuery', () => {
expect(result.size).toBe('small');
expect(result.name).toEqual('Product 3');
expect(result.className).toEqual('Item');

await q.each((obj) => {
expect(obj.objectId).toBe('I1');
expect(obj.size).toBe('small');
expect(obj.name).toEqual('Product 3');
expect(obj.className).toEqual('Item');
}, { json: true });
});

it('will error when getting a nonexistent object', done => {
Expand Down