-
-
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
Allow cloud code file to be an array of files or a folder #6962
Conversation
Danger run resulted in 1 fail and 1 markdown; to find out more, see the checks page. Generated by 🚫 dangerJS |
Codecov Report
@@ Coverage Diff @@
## master #6962 +/- ##
==========================================
+ Coverage 93.78% 93.81% +0.02%
==========================================
Files 169 169
Lines 12269 12281 +12
==========================================
+ Hits 11507 11521 +14
+ Misses 762 760 -2
Continue to review full report at Codecov.
|
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.
Thanks for the PR! I have few comments about the code.
In addition, it is kinda strange to me to have multiple entry points for cloud code. Most of the frameworks that I know have a single entry point, from which the developers decide what more they want to load. On the other hand, I don't see any problem in having multiple entry points, except that, for the case of the directory, we can't ensure a specific order in which the files will be loaded. @dplewis @mtrezza @Moumouls thoughts?
If I understand this PR correctly, the advantage is that instead of adding
|
Here i see some issues i found. In full CLI usage i understand the idea. Currently the // _User.js
Parse.Coud.define(xxxxx) // main.js
modules.exports = () => { require('./_User')} //server.js
const cloudCode = require('./main')
ParseServer.start({
...params,
cloud: cloudCode
}) I'm currently using a similar solution with Typescript support and it work like a charm If you want a more concrete example see my repo (in TS): Personally I'm not sure this addition is a good idea, we will have many issues in the futur since parse server is not an importer system (like webpack) Finally, i think that here we have a lack of best practice on cloud code guide, the cloud code as function is not correctly documented 😄 In any case @dblythy , thank you anyway to propose PRs it is always a plus for the evolution of Parse. |
Correct. Even though require is pretty easy to use, breaking up the cloud code was one thing I personally struggled to get my head around when I started with Parse, as I'd had no JS / backend experience. A lot of my PRs are around highlighting things that trapped me earlier on that I could've done better, had've I known what I was doing 😂.
Yes, according to my testing it registers all Parse.Cloud functions as expected.
You would still have to require jsonParser.js in each individual file I believe. If you'd like me to write a test case for that I can.
I didn't think about that. I was more giving focused on the Parse.Cloud functions, but if we revisit this in the future, we can look at that.
I'm unfamiliar with Typescript, so thanks for pointing that out! Thank you for your feedback @mtrezza, @Moumouls, and @davimacedo! It seems that this will incur more problems than it'll solve. So i'll close this now. Thanks all! |
Sorry again for submitting so many PRs, I've had a few ideas of how to improve my Parse Server I thought I'd share with the community.
For my backend, I like to break down my functions by class name, and then import the files in main.js (e.g /cloud/functions contains "_User.js", which has all user
beforeSave
andafterSave
functions, and anyParse.Cloud.define
functions relevant toParse.User
).This PR allows the cloud parameter to be a folder, where all .js files will be imported, or an array of files. This allows users to have more, smaller, organised cloud files, which in my experience, makes it easier to navigate.