Functions
Run server-side TypeScript in Rayfin with typed frontend calls, typed secrets, and app-identity connections to Azure and Fabric resources.
Rayfin functions are server-side TypeScript user-defined functions (UDFs) authored with @microsoft/fabric-user-data-functions, run in the Fabric runtime, and invoked from your frontend through RayfinClient. Use them for trusted backend logic, secrets, and external resource calls that must not run in the browser.
Note
Functions are generally available in Rayfin 1.36 and no longer use a RAYFIN_FEATURE_FLAGS=functions gate. They are not available in every Fabric region or tenant; confirm deployment in the target workspace before you depend on them.
Use a function for trusted server work
Use a function when code needs a server boundary:
- Secrets and API keys — read values with
ctx.Secrets, never from client code. - Business logic users must not edit — enforce rules that a browser client could bypass.
- Server-side validation — validate before writing data or calling external services.
- Aggregation and transformation — combine data before returning it to the frontend.
- External resources — call Fabric SQL, OneLake, Fabric REST, Azure AI Foundry, or Azure DevOps with server-side tokens.
For normal reads and writes against your Rayfin entities, call client.data.<Entity> from the frontend instead of adding a function hop.
Enable and scaffold functions
Run functions init from an existing Rayfin project:
npx rayfin functions initThe command creates the functions package, enables the service in rayfin/rayfin.yml, installs dependencies, builds, and generates the initial types.ts schema.
services:
functions:
enabled: true
path: rayfin/functions
auth:
type: application
buildCommand: npm run buildauth.type: application is required when Functions are enabled. New 1.36 scaffolds write it automatically; existing apps must add it explicitly and run a full npx rayfin up to apply the remote setting. Standalone commands such as npx rayfin up functions deploy upload code but do not migrate the remote auth mode.
Understand the two identities
Deployed functions use two authentication paths:
| Access path | API | Identity used |
|---|---|---|
| Rayfin data | ctx.getDataClient() | The signed-in caller's Rayfin token and database permissions. |
| External resources | ctx.Tokens.<Audience> | The Fabric app's application identity. For current Fabric apps, this is the owner of the Fabric app item. |
Grant external resources to the app identity. Declaring an audience or deploying the function does not grant SQL, Storage, Fabric REST, Azure AI, or Azure DevOps permissions.
Project structure
rayfin/
data/
functions/
src/
function_app.ts
types.ts
secrets.generated.ts
host.json
local.settings.json
package.json
tsconfig.jsonfunction_app.tsregisters handlers withudf.func(...).types.tsis generated for frontend calls; never hand-edit it.secrets.generated.tsis generated from the top-levelsecrets:list inrayfin.yml; never hand-edit it.local.settings.jsonis local-only and can contain local development secrets.
Development and deployment loop
Prefer npx rayfin dev during development. It provisions or reuses the Fabric backend, emits frontend environment files, starts the frontend, and starts the local Functions host when services.functions.enabled is true.
Use these focused commands when needed:
| Task | Command |
|---|---|
| Scaffold or refresh the functions package | npx rayfin functions init |
| Run only the local Functions host | npx rayfin dev functions apply |
| Deploy everything, including functions | npx rayfin up |
| Deploy only function code | npx rayfin up functions deploy |
| Skip function deployment in a full deploy | npx rayfin up --exclude-services functions |
In this section
- Writing a function — register handlers, use
RayfinContext, and keep generated types current. - Secrets in functions — declare secrets with the CLI and read them through
ctx.Secrets. - Connections — use application-auth tokens for Fabric and Azure resources.
- Calling functions from your app — invoke functions through
RayfinClient. - Run functions locally — start, route, debug, and troubleshoot the local host.
- Deploying functions — deploy functions with
rayfin uporrayfin up functions deploy.
In my Rayfin project, add a server-side function for this task: <describe the trusted backend logic>.
Use Rayfin 1.36 or later. If rayfin/functions/ does not exist, run `npx rayfin functions init`. Ensure rayfin/rayfin.yml has services.functions.enabled: true and services.functions.auth.type: application. Register the handler in rayfin/functions/src/function_app.ts with `udf.func(name, handler, [])`. Use `RayfinContext<AppSchema>` for typed data access, `ctx.Secrets.<NAME>` for declared secrets, and `RayfinContext<AppSchema, AudienceType.X>` plus `ctx.Tokens.X` for external resources. Do not expose secrets or tokens to the frontend. Run the smallest build or typegen command that validates the change, then tell me how to call the function from the frontend.