# Cloud Function Triggers
Cloud function triggers allow app developers to inject custom code into the GraphQL mutation resolver pipeline. Functions are executed either before or after the auto-generated default resolvers.
Before-Triggers are primarily used for data validation, data enrichment, fine-granular access checks, or setting default values, to name a few. App developers can use After-Triggers for sending notifications or other follow-up actions after a successful creation, update, or deletion of entries.
# Quickstart Guide
- Create and publish a dedicated low-code backend by completing the Project Wizard
- Implement and upload your cloud function e.g. by copy & pasting the source file into the cloud function window of your API:
- After the file is uploaded reference it as a trigger from one of your object types. Define if it should be executed as a before- or after-step and for which mutation type (create/update/delete) it should be executed.
- Republish your project for the changes to take effect.
- Validate if the function works by creating/updating/deleting an entry
TIP
Subsequent changes of a specific cloud-function don't require republishing
# Supported Runtimes
The following runtimes are supported:
- Node.js v18
- Python v3.10
- Ruby v2.7
When uploading Cloud Functions the runtime is mapped based on the file extension as follows:
.js
,.mjs
,.cjs
-> Node.js v18.py
-> Python v3.10.rb
-> Ruby v2.7
TIP
By default, cloud functions with a .js
suffix are treated as CommonJS modules. To designate your code as an ES module use the .mjs
file extension.
# Examples
The following code example shows a simple Node.js handler function using CommonJS syntax. The function gets the input object from the GraphQL mutation arguments and amends the field someField
or sets a default value when it is missing.
By returning an object with a subset of fields matching the original input type a developer can simply overwrite values which have been passed to the original GraphQL mutation request.
// Example of a Node.js before-trigger function
exports.handler = async function (event, context) {
const input = event.arguments.input;
const someField = input.someField
? `${input.someField} has been edited`
: "defaultValue";
return {
someField,
};
};
2
3
4
5
6
7
8
9
10
11
A similar Python function amending a field someField
looks as follows. In this example an empty dictionary is returned when someField
is not present. Please note that returning an empty dictionary from the handler function does not overwrite the original input arguments.
def handler(event, context):
input = event.get('arguments').get('input')
someField = input.get('someField')
if not someField:
return {}
newValue = '{} has been edited!'.format(someField)
return {
'someField' : newValue
}
2
3
4
5
6
7
8
9
10
TIP
Get started quickly and grab a template function from our Github repo (opens new window)