Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.modelence.com/llms.txt

Use this file to discover all available pages before exploring further.

API Reference / modelence / client / callMethod
callMethod<T>(methodName, args?, options?): Promise<T>
Defined in: packages/modelence/src/client/method.ts:58 Calls a server-side method (query or mutation) defined on a Modelence module. Both args and options are optional. Use the type parameter T to type the return value.

Example

import { callMethod } from 'modelence/client';

// No arguments
const todos = await callMethod<Todo[]>('todo.getAll');

// With arguments
const todo = await callMethod<Todo>('todo.getOne', { id: '123' });

// With a custom error handler
const created = await callMethod<Todo>(
  'todo.create',
  { title: 'Buy groceries' },
  { errorHandler: (error, methodName) => console.error(methodName, error) }
);

Type Parameters

Type ParameterDefault type
Tunknown

Parameters

ParameterTypeDescription
methodNamestringFully qualified method name, e.g. 'todo.getAll'.
args?MethodArgsArguments passed to the server-side method. Defaults to {}.
options?CallMethodOptionsCall-site options such as a custom CallMethodOptions.errorHandler. Defaults to {}.

Returns

Promise<T> A promise that resolves to the method’s return value.