-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat: Allow short circuit of beforeFind #8694
base: alpha
Are you sure you want to change the base?
Conversation
I will reformat the title to use the proper commit message syntax. |
Thanks for opening this pull request! |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## alpha #8694 +/- ##
==========================================
+ Coverage 94.33% 94.36% +0.02%
==========================================
Files 185 185
Lines 14766 14773 +7
==========================================
+ Hits 13930 13941 +11
+ Misses 836 832 -4
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea, I just wonder whether client SDKs is equipped for that.
I assume the results of a query until this PR are always saved objects with objectId, createdAt and updatedAt being set. Could there be unexpected behavior if a query returns "made up" objects that don't exist in the DB and are without those properties?
We could still merge the PR, as the feature would be usable via the REST API, but the docs would need a caveat note.
Also can Parse Server internally handle that in all situations? For example, in combination with explain
option, etc.
Signed-off-by: Manuel <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good; just one thing you surely have thought about already:
Should afterFind
really not run because beforeFind
substitutes the DB result? In theory one doesn't have to exclude the other, i.e. returning a result in beforeFind
could skip the DB operation but still run the afterFind
logic on the returned object. I'm thinking in cases were the afterFind
block manipulates objects in a certain way, and one would want all objects to run through that. One could still differentiate between beforeFind
-generated results and DB results by passing a flag in the context
container.
It could cause issues for a strongly typed language such as Swift, if an object is returned that has not been saved ( |
Is that really a "strongly typed" question? Or do you mean that (any) Parse client SDK may expect a returned object to have a |
The JS SDK can handle "unsaved" objects, i'm not sure whether other SDKs can just yet. Regarding the |
Then what do you mean by
Doesn't the same argument apply when returning an object from beforeSave? The object can be the same, whether it's returned from |
Yes you are correct. So I think this should be safe to merge for other SDKs. |
I think so, and I think the docs should explain that, because the developer is interfering in something that Parse Server would do internally, i.e. compose the query results. That's even more difficult than modifying the results in I think there are 2 open points:
|
It's only possible to return Parse Objects, and If an object with a different class name is returned, which
|
They are set even if a Parse Object is returned when these fields a not set? For example if const MyClass = Parse.Object.extend("MyClass");
const o = new MyClass();
o.a = 1;
return [o];
So a query on class
Maybe we should even check in code whether the return value complies with these requirements and throw an error otherwise. This would help developers to ensure they are composing compliant return values. |
It’s probably worth mentioning that the same concerns regarding fields, matching className, etc, apply to the current implementation of the afterFind trigger - there aren’t any restrictions what can be returned there (in fact, json that does not conform to a parse object can be returned) |
Yes, I think we discovered a lack of documentation / restriction. We don't know whether Parse Server can handle this change of return values in all scenarios, and for the SDKs we currently don't know how they behave, nor do we have the test set-up to test this out in the CI. Your question already indicates that we are going down a slippery slope. If we allow (per docs or code) any return type or even return a different class than was queried, then we cannot guarantee that Parse Server or the Parse client SDKs are able to handle this (not just for strongly typed languages). I think the |
This makes me think about something I'm thinking a lot, It's not better to have a version of parse server only as API? Ignoring that clients' SDKs exist? For example, I don't use the client SDKs, I have my own handles when I want to have a different return I send a type param (ie: 'search', profileList') and send It to the afterFind as a context to manage to have a different result. It would give more freedom to work as a backend and make customizations, maybe a key on the config file. For example, now I want to customize the JSON returning on an aggregation query, but it doesn't work well with Parse Server. |
What concept do you have in mind?
With a Cloud Function you are free to return anything. |
Nothing special, just a focused backend version. hehehe
Yes for sure, but I don't want to have a lot of endpoints as POST that are supposed to be GET. But as I'm saying, I'm customizing on before/after find and not using the client's and it works. Just have to be organized. |
What is a "focused backend version"? Not sure I understand what change you are suggesting.
I'm sure Cloud Functions could easily support GET requests (if they don't already do this). However this seems to be off topic; if you would like to open a feature request for that please search for existing issues and if necessary open a new issue. |
Sorry, I'm suggesting nothing, just this PR made me think about how the client's SDKs can make it harder to do some stuff, but as you said, it's possible to use cloud functions. |
Got it, feel free to open a feature request for Cloud Functions for GET requests in a separate issue, if it's not already supported. |
@dblythy Do you want to try to get this over the finish line? I believe this is almost done. |
Pull Request
Issue
Closes: #8693
Approach
Adds ability to return objects (or an empty array) from a
beforeFind
trigger.Tasks