Skip to content

add context to Parse.Object.save #1150

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 4 commits into from
Apr 21, 2020

Conversation

mtrezza
Copy link
Member

@mtrezza mtrezza commented Apr 18, 2020

Exposes the context object in Parse.Object.save() so that parameters can be made accessible in Cloud Code triggers beforeSave, afterSave.

Example:

const obj = new TestObject();
await obj.save(null, {context: {a: "a"}});

Parse.Cloud.beforeSave("TestObject", req => {
    console.log(req.context.a);
});

Parse.Cloud.afterSave("TestObject", req => {
    console.log(req.context.a);
});  

Don't merge until

@mtrezza mtrezza changed the title add context to save add context to Parse.Object.save Apr 18, 2020
- context is transmitted as `_context` property in REST request
- given that a leading underscore `_` marks a reserved property
@codecov
Copy link

codecov bot commented Apr 18, 2020

Codecov Report

Merging #1150 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1150   +/-   ##
=======================================
  Coverage   92.30%   92.31%           
=======================================
  Files          54       54           
  Lines        5235     5241    +6     
  Branches     1169     1171    +2     
=======================================
+ Hits         4832     4838    +6     
  Misses        403      403           
Impacted Files Coverage Δ
src/ParseObject.js 89.61% <100.00%> (+0.02%) ⬆️
src/RESTController.js 84.90% <100.00%> (+0.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7cf413e...8201392. Read the comment docs.

@mtrezza
Copy link
Member Author

mtrezza commented Apr 18, 2020

The context is transmitted as _context property in REST request body as part of the object properties.

I did not find an existing similar use of internal properties in the REST request, but according to the docs a field name must start with a letter, so there cannot be a conflict with an object property:

Key names must contain only numbers, letters, and underscore, and must start with a letter.

So using _context as internal property in a REST request seems OK, it is also used for internal field names such as _created_at in the DB.

Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick comment

Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I will try to do a release soon

@dplewis dplewis merged commit e6ab6c3 into parse-community:master Apr 21, 2020
@mtrezza
Copy link
Member Author

mtrezza commented Apr 21, 2020

Thanks! Would be great if you could make a release with parse server release that will merge parse-community/parse-server#6626.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants