Functions:DataAPI - bettyblocks/cli GitHub Wiki

DataAPI

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:


Read

Example:

const query = `
  query {
    onePost(where: $where) {
      id
      title
    }
  }
`;
const {data, errors} = await gql(query, { where: { id: { eq: id } } });

Create

Example:

const mutation = `
  mutation {
    createPost(input: $input) {
      id
    }
  }
`;
const {data, errors} = await gql(mutation, { input: { title: "New Post" } });

Update

Example:

const mutation = `
  mutation {
    updatePost(id: $id, input: $input) {
      id
    }
  }
`;
const {data, errors} = await gql(mutation, { id: id, input: { title: "Updated Post" } });

Delete

Example:

const mutation = `
  mutation {
    deletePost(id: $id) {
      id
    }
  }
`;
const {data, errors} = await gql(mutation, { id: id });