Global Actions

This page documents all the root level mutations powered by Global Actions in the alida-quiz-app-2 API.

Action Result format

Each API action returns results in the same format that includes a success indicator, errors, and the actual result if the action succeeded. The result is the record that was acted on for a model action, or a list of records for a bulk action, or a JSON blob for Global Actions. Model actions that delete the record don't return the record.

The success field returns a boolean indicating if the action executed as expected. Any execution errors are returned in the errors object, which will always be null if success is true or contain ExecutionError objects if success is false.

ExecutionError objects always have a message describing what error prevented the action from succeeding, as well as a code attribute that gives a stable, searchable, human readable error class code for referencing this specific error. Details on each error code can be found in the Errors documentation. All ExecutionError object types returned by the GraphQL object can be one of many types of error, where some types have extra data that is useful for remedying the error. All error types will always have message and code properties, but some, like InvalidRecordError have extra fields for use by clients.

Errors when using the generated client

The generated JavaScript client automatically interprets errors from invoking actions and throws JavaScript Error instances if the action didn't succeed. The Error objects it throws are rich, and expose extra error properties beyond just message and code if they exist.

Errors thrown by the JavaScript client are easiest to catch by using a try/catch statement around an await, like so:

1import {
2 GadgetOperationError,
3 InvalidRecordError,
4} from "@gadget-client/example-app";
6// must be in an async function to use `await` syntax
7const runAction = async () => {
8 try {
9 return await api.exampleModel.create({
10 exampleModel: { name: "example record name" },
11 });
12 } catch (error) {
13 if (error instanceof GadgetOperationError) {
14 // a recognized general error has occurred, retry the operation or inspect error.code`
15 console.error(error);
16 } else if (error instanceof InvalidRecordError) {
17 // the submitted input data for the action was invalid, inspect the invalid fields which `InvalidRecordError` exposes
18 console.error(error.validationErrors);
19 } else {
20 // an unrecognized error occurred, like an HTTP connection interrupted error or a syntax error. Re-throw it because it's not clear what to do to fix ti
21 throw error;
22 }
23 }

For more information on error codes, consult the Errors documentation.



globalShopifySync accepts the following input parameters

globalShopifySync Input
1export interface GlobalShopifySyncArguments {
2 /** An array of Strings */
3 apiKeys?: (Scalars["String"] | null)[];
5 syncSince?: Date | Scalars["ISO8601DateString"] | null;
7 /** An array of Strings */
8 models?: (Scalars["String"] | null)[];
1input GlobalShopifySyncArguments {
2 """
3 An array of Strings
4 """
5 apiKeys: [String!]
6 syncSince: DateTime
8 """
9 An array of Strings
10 """
11 models: [String!]
Example globalShopifySync Invocation
const result = await api.globalShopifySync();
console.log(result); //=> a JSON blob returned by the global action
const [result, globalShopifySync] = useGlobalAction(api.globalShopifySync);
const { data, error, fetching } = result;
await globalShopifySync();
console.log(; //=> a JSON blob returned by the global action
1mutation ($apiKeys: [String!], $syncSince: DateTime, $models: [String!]) {
2 globalShopifySync(apiKeys: $apiKeys, syncSince: $syncSince, models: $models) {
3 success
4 errors {
5 message
6 }
7 result
8 }

globalShopifySync returns whatever data the effects within it produce.

globalShopifySync Output
type GlobalShopifySyncResult {
success: Boolean!
errors: [ExecutionError!]
result: JSON

Returning data

You may choose to return data when running a global action. You can do so by assigning a value to scope.result. This variable accepts any data type you wish.

module.exports = async ({ api, scope, logger }) => {
// scope.result = "Hello, World";
// scope.result = 12345;
// scope.result = { hello: "world" }