Skip to content

Modernization of hooks and functions #4930

@flovilmart

Description

@flovilmart

Is your feature request related to a problem? Please describe.

Right now, we still rely on the legacy backbone style success / error callback methods. With node.js moving forward at an incredible pace, I believe it's time to make the cloud functions enter the 21st century supporting async / await, promises and more

Describe the solution you'd like

  • Support promises, async/await in cloud code as valid return values for hooks and functions
  • Mark calls to success / error callbacks deprecated in Cloud Code (with a big fat warning)
  • Later on, remove success / error implementations

Cloud funcitons would look like:

Parse.Cloud.beforeSave('ClassName', async ({ object }) => {
    await doSomething();
    if (somethingsFishy(object)) {
        throw new Error('OOps')
    }
    return;
});

// Also valid
Parse.Cloud.beforeSave('ClassName', async ({ object }) => {
    await doSomething();
    if (somethingsFishy(object)) {
        return new Error('OOps'); // returning an error is also allowed
    }
});

For functions:

Parse.Cloud.define('MyFunction', async ({ params }) => {
    await doSomething();
    if (!param.isValid) {
        return new Error('OOps'); // returning an error is also allowed
    }
    return 'OK!';
});

cc: @acinader , @dplewis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions