-
Notifications
You must be signed in to change notification settings - Fork 16
Functions:DataAPI
Thomas Timmer edited this page Sep 16, 2024
·
4 revisions
In order to work with application data in functions, the runtime exposes the gql
helper, which connects with the DataAPI.
All of the queries available in the DataAPI are available with the gql helper.
Next to this, we also supported mutations to create, update and delete data.
For more info/details on DataAPI Mutations
Couple of examples:
Example:
const query = `
query {
onePost(where: $where) {
id
title
}
}
`;
const {data, errors} = await gql(query, { where: { id: { eq: id } } });
Example:
const mutation = `
mutation {
createPost(input: $input) {
id
}
}
`;
const {data, errors} = await gql(mutation, { input: { title: "New Post" } });
Example:
const mutation = `
mutation {
updatePost(id: $id, input: $input) {
id
}
}
`;
const {data, errors} = await gql(mutation, { id: id, input: { title: "Updated Post" } });
Example:
const mutation = `
mutation {
deletePost(id: $id) {
id
}
}
`;
const {data, errors} = await gql(mutation, { id: id });
- Getting started
- Page Builder Components
- Action Functions
- [deprecated] CustomFunctions