AGENT SKILL

Web 应用接入 Fabric 数据源

fabric-sdk

如何使用 @microsoft/fabric-app-data 在运行时将 Web 应用程序连接到 Fabric 数据源。构建基于浏览器的应用,通过 FabricClient API 使用 DAX 查询语义模型。

License 许可
MIT
最近更新
2026-11-14
Stars
★ 23
Forks
5

01 前言 Front Matter

name
fabric-sdk
description
How to use @microsoft/fabric-app-data to connect web applications to Fabric data sources at runtime. Build browser-based apps that query semantic models via DAX using the FabricClient API.

02 资源文件 12

03 SKILL.md 正文

Fabric SDK Usage

Overview

@microsoft/fabric-app-data lets web applications query Fabric semantic models at runtime. The SDK provides a FabricClient that handles querying, result parsing, caching, and error handling. Transport and authentication are delegated to an IFabricApiProxy implementation, keeping the SDK environment-agnostic (browser, Node.js, Fabric extensions).

Quick Start

import { FabricClient } from "@microsoft/fabric-app-data";

const client = new FabricClient({
  proxy,                               // provided by host environment
  semanticModels: {
    sales: { workspaceId: "...", itemId: "..." },
  },
});

const result = await client.semanticModel("sales").query(
  "EVALUATE SUMMARIZECOLUMNS(Product[Category], \"Total\", [Sales Amount])"
);

if (result.status === "success") {
  // result.table.columns — [{name, dataType}]
  // result.table.rows    — unknown[][]
} else {
  // result.error.category — "api" | "query" | "overflow" | "network" | "unknown"
  // result.error.message
}

Key Concepts

FabricClient Configuration

The FabricClient is constructed with a config object. The proxy and connection details are typically provided by the host environment — your code just needs to pass them through:

new FabricClient({
  proxy,                               // Provided by host environment
  semanticModels: {                    // Named connections
    alias: { workspaceId, itemId },
  },
  cache: {                             // Optional
    enabled: true,                     // Default: true
    maxEntries: 64,                    // Default: 64 (LRU eviction)
  },
});
  • workspaceId can be a GUID or "me" for My Workspace items.

Managing Connections

The FabricClient accepts connection config as a plain object. How you manage those IDs (environment variables, config files, codegen) is up to your project. The only requirement is that workspaceId and itemId are provided for each named connection.

const client = new FabricClient({
  proxy,
  semanticModels: {
    sales: { workspaceId: "00c98f7c-...", itemId: "03f2dc11-..." },
  },
});

Querying

There is one method for DAX queries:

const result = await client.semanticModel("alias").query(dax);

// To skip the cache:
const fresh = await client.semanticModel("alias").query(dax, { bypassCache: true });

Result Handling

Always check result.status — queries never throw.

Each query must contain exactly one EVALUATE statement. On success, the result contains a single table with:

  • columns: Array<{ name: string, dataType: string }> — column metadata
  • rows: unknown[][] — row-major array, values match column order by index
const result = await model.query("EVALUATE ...");

if (result.status === "success") {
  // result.table.columns = [{ name: "Product[Name]", dataType: "String" },
  //                          { name: "[Sales]", dataType: "Int64" }]
  // result.table.rows    = [["Widget", 42], ["Gadget", 17]]
  // result.table.rows[0][0] → "Widget" (matches columns[0])
  // result.table.rows[0][1] → 42       (matches columns[1])
} else {
  console.error(result.error.message);
  // result.error.category: "query" (bad DAX), "overflow" (value too large),
  //                        "api" (HTTP error), "network" (connectivity), "unknown"
}

Caching

Results are cached in memory by default (LRU, 64 entries).

const r1 = await model.query("EVALUATE T");  // r1.fromCache === false
const r2 = await model.query("EVALUATE T");  // r2.fromCache === true

// Check cache age
if (r2.fromCache && r2.cachedAt) {
  const ageMs = Date.now() - r2.cachedAt.getTime();
}

// Force fresh result
const fresh = await model.query("EVALUATE T", { bypassCache: true });

// Clear cache
client.clearCache();                          // all sub-clients
model.clearCache();                           // this model only

What gets cached:

  • ✅ Success results
  • ✅ Query errors (bad DAX — won't fix itself)
  • ❌ API errors (401, 500 — transient)
  • ❌ Network errors (transient)

Error Categories

Category Meaning Cached? Example
query Invalid DAX syntax Yes "Syntax error at position 18"
overflow Integer/decimal exceeds safe range Yes Value > MAX_SAFE_INTEGER
api HTTP error from Fabric No 401 Unauthorized, 500 Server Error
network Connection failure No DNS resolution, timeout
unknown Unexpected error No Parse failure

Data Types and DateTime Semantics

The SDK converts all DAX data types to standard JS values:

DAX type JS value type Example
Integer (Int64) number 42
Double (Float64) number 3.14
Currency/Decimal number 100.50
Boolean boolean true
String string "hello"
DateTime/Date string (ISO) "2024-01-15T10:30:00.000"
BLANK null null

DateTime values are returned as ISO 8601 strings without a timezone suffix (no Z, no ±HH:MM). This matches the semantics of Analysis Services semantic models, where datetimes are timezone-unaware.

// DateTime column values look like:
"2024-01-15T10:30:00.000"   // no timezone — interpret as-is
"2023-06-01T00:00:00.000"

This format is directly usable as a temporal type in charting libraries and ensures consistent display across all browser timezones. The JSON and Arrow protocols both return the same format.

Integer overflow: If an integer value exceeds ±Number.MAX_SAFE_INTEGER (±9,007,199,254,740,991), the query returns an error with category: "overflow" rather than silently losing precision.

Common Patterns

Multiple Models

const client = new FabricClient({
  proxy,
  semanticModels: {
    sales: { workspaceId: "ws-1", itemId: "item-1" },
    inventory: { workspaceId: "ws-2", itemId: "item-2" },
  },
});

const salesResult = await client.semanticModel("sales").query("EVALUATE ...");
const invResult = await client.semanticModel("inventory").query("EVALUATE ...");

My Workspace Items

semanticModels: {
  myModel: { workspaceId: "me", itemId: "..." },
}

Disabling Cache

new FabricClient({
  proxy,
  cache: { enabled: false },
  semanticModels: { ... },
});

Anti-Patterns

  • Don't catch errors from query() — it never throws. Check result.status.
  • Don't hardcode endpoint URLs — the proxy handles transport.
  • Don't construct SemanticModelClient directly — use client.semanticModel(alias).
  • Don't import from internal paths — only import from "@microsoft/fabric-app-data".

Type Reference

All types are exported from the "@microsoft/fabric-app-data" package entry point.

Key types to import when needed:

import type {
  FabricClientConfig,
  FabricItemRef,
  QueryResult,
  CachedQueryResult,
  QueryCacheOptions,
  QueryTable,
  QueryColumn,
  QueryError,
} from "@microsoft/fabric-app-data";

For full type definitions, see references/types.md in this skill.

04 同仓库更多 Skills

microsoft
microsoft/ValueLens-for-Microsoft-Copilot

数据可视化组件开发

visuals

当用户希望在项目中使用图表、图形、数据网格或其他数据可视化形式时使用。使用 VegaVisual 和 DataGrid 组件创建这些可视化,利用共享的 DataTable 输入、格式化、主题和交互能力。涵盖每个可视化默认获得的 VisualContainer 外观框架、宿主应用消费的 onInteraction 选择/点击事件、用于分层叠加和参考线的命名多表数据输入,以及 Vega-Lite 原生选择功能。

软件开发工程师前端开发与界面实现
★ 23
microsoft
microsoft/ValueLens-for-Microsoft-Copilot

schema-discovery

Explore Power BI semantic model schemas using DAX INFO functions. Progressive metadata discovery strategy, scope estimation, and narrowing techniques for tables, columns, measures, and relationships.

★ 23
microsoft
microsoft/ValueLens-for-Microsoft-Copilot

query-design

Separates DAX data-fetching from TypeScript presentation. Guides when to use DAX vs. TypeScript vs. Vega-Lite for aggregation, total rows, FORMAT(), SELECTCOLUMNS, BLANK handling, filtering, multi-grain queries, cross-filtering and cross-highlight subset/overlay queries, and format strings.

★ 23
microsoft
microsoft/ValueLens-for-Microsoft-Copilot

Playwright 浏览器自动化测试

playwright-cli

自动化浏览器交互、测试网页,并使用 Playwright 开展测试。

测试工程师测试与质量保障
★ 23
microsoft
microsoft/ValueLens-for-Microsoft-Copilot

Fabric 数据源连接管理

fabric-cli

如何使用 fabric-app-data CLI 管理 Fabric 数据源连接。在 fabric.yaml 文件中通过配置档案维护工作区/项目 ID,通过 ID 或 Fabric 门户 URL 添加连接,并生成 TypeScript 配置以供 @microsoft/fabric-app-data 使用。

数据工程师应用连接器集成
★ 23
microsoft
microsoft/ValueLens-for-Microsoft-Copilot

DAX 查询编写与测试

dax-authoring

针对 Power BI 语义模型编写和测试 DAX 查询。涵盖 DAX 语法规则、查询模式、时间智能,以及使用 Fabric CLI query 命令的迭代测试工作流。

数据分析师数据分析与报告
★ 23