Skip to main content

App Data Provider

App-level configuration, edge function execution, and analytics queries — all through a single provider.

Setup

<Refine
dataProvider={{
default: dataProvider(client),
app: appDataProvider(client),
}}
/>

Fetch Roles

const { result, query } = useList({ resource: "roles", dataProviderName: "app" });
// result.data → [{ id, name, permissions, ... }], result.total → number

Fetch Settings

const { result, query } = useOne({ resource: "settings", dataProviderName: "app", id: "" });
// result.data → { ...app settings object }

Execute Edge Functions

Use useCustom with meta.kind: "function". The url is the function slug, and config.payload contains the parameters.

import { useCustom } from "@refinedev/core";

const { data, isLoading } = useCustom({
dataProviderName: "app",
url: "process-order",
method: "post",
config: {
payload: { orderId: 123, action: "confirm" },
},
meta: { kind: "function" },
});

// Async execution (returns immediately with job ID)
useCustom({
dataProviderName: "app",
url: "long-running-task",
method: "post",
config: { payload: { taskId: 789 } },
meta: { kind: "function", async: true },
});

Execute Analytics Queries

Use useCustom with meta.kind: "analytics". The url is the query slug.

const { data } = useCustom({
dataProviderName: "app",
url: "monthly-sales-report",
method: "post",
config: {
payload: { start_date: "2024-01-01", end_date: "2024-12-31", region: "US" },
},
meta: { kind: "analytics" },
});

App Custom Meta Types

import type { FunctionMeta, AnalyticsMeta, AppCustomMeta } from "@taruvi/refine-providers";

// FunctionMeta: { kind: "function"; async?: boolean }
// AnalyticsMeta: { kind: "analytics" }
// AppCustomMeta: FunctionMeta | AnalyticsMeta