This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
In today's data-driven world, the ability to quickly expose data through modern APIs is crucial. Microsoft Fabric's API for GraphQL combined with Materialized Lake Views offers a powerful solution that bridges the gap between your Fabric LakeHouse data and application developers who need fast, flexible access to your data.
In this guide, we'll walk you through how to create a materialized view in a Lakehouse and expose it through a GraphQL API—all within the Microsoft Fabric ecosystem. This approach gives you the best of both worlds: the performance optimization of materialized views and the developer-friendly querying capabilities of GraphQL.
Before we dive into the how-to, let's understand why this matters:
The result? Data engineers can optimize query performance while application developers get fast, intuitive API access—without compromising on either side.
In this tutorial, we'll use the LakeHouse sample Wide World Importers retail dataset to create a practical example. We'll:
Let's get started!
First, we need to create a Lakehouse with schema support enabled. This must be done during the lakehouse creation process.
Now let's populate it with sample data:
Within moments, your Lakehouse will be populated with realistic retail data in the dbo schema, including dimension tables (cities, customers, employees, stock items) and the fact_sale table. This dataset mirrors real-world retail scenarios, making it perfect for demonstrating enterprise use cases.
Note: Lakehouse schemas is currently in Preview. Once enabled during creation, you cannot disable schemas for that lakehouse. If you have an existing lakehouse without schemas, you'll need to create a new one with schemas enabled.
Now let's create a materialized lake view using a notebook. Unlike traditional SQL views, materialized lake views in Fabric are created using Spark SQL in notebooks and are automatically managed by the platform.
Important: Materialized lake views require Fabric Runtime 1.3 or later. Make sure your workspace is configured to use Runtime 1.3 before proceeding.
In the notebook, create a materialized lake view that aggregates sales metrics:
%%sql
CREATE MATERIALIZED LAKE VIEW IF NOT EXISTS dbo.SalesByStockItemAndCity
COMMENT "Sales metrics aggregated by stock item and city"
AS
SELECT
si.StockItem,
si.Brand,
si.Color,
c.City,
c.StateProvince,
c.Country,
COUNT(DISTINCT fs.SaleKey) as TotalSales,
SUM(fs.Quantity) as TotalQuantity,
SUM(fs.TotalExcludingTax) as TotalRevenue,
SUM(fs.Profit) as TotalProfit,
AVG(fs.UnitPrice) as AverageUnitPrice
FROM dbo.fact_sale fs
INNER JOIN dbo.dimension_stock_item si ON fs.StockItemKey = si.StockItemKey
INNER JOIN dbo.dimension_city c ON fs.CityKey = c.CityKey
GROUP BY si.StockItem, si.Brand, si.Color, c.City, c.StateProvince, c.Country;
This view pre-computes key metrics across the fact and dimension tables. The beauty of materialized lake views is that Fabric automatically manages the refresh logic and dependency tracking—you just define what you want, and Fabric handles how to maintain it.
Exposing_Lakehouse_Materialized_Views_to_applications_in_minutes_with_GraphQL_AP
One of the powerful features of materialized lake views is the automatic lineage tracking and refresh scheduling.
Fabric intelligently manages the refresh process—if source data hasn't changed, the view won't be needlessly recomputed, saving capacity and compute resources. You can monitor ongoing and historical runs from the dropdown menu to track execution status and performance.
Here's where the magic happens—we'll expose our materialized lake view through a GraphQL API with just a few clicks.
That's it! Fabric automatically generates a fully-functional GraphQL schema based on your materialized view structure. The schema includes queries for fetching data with filtering, sorting, and pagination built in.
Now you can query your data using GraphQL. The API for GraphQL includes a built-in API explorer that makes testing queries easy.
The following is an example query to fetch top-performing products in specific regions:
query TopProductsByRegion {
salesbystockitemandcities(
filter: {
Country: { eq: "United States" }
TotalRevenue: { gt: 50000 }
}
orderBy: { TotalProfit: DESC }
first: 10
) {
items {
StockItem
Brand
Color
City
StateProvince
TotalSales
TotalQuantity
TotalRevenue
TotalProfit
AverageUnitPrice
}
}
}
The beauty of GraphQL is that application developers can request exactly the fields they need. Want just product names and profit margins? Need to filter by brand or color? Simply modify the query—no need to create new API endpoints.
Exposing_Lakehouse_Materialized_Views_to_applications_in_minutes_with_GraphQL_AP
This integration delivers three key benefits:
Performance: Materialized views pre-compute complex aggregations, while GraphQL's efficient data fetching ensures clients get only what they need. The combination means fast queries at both the data layer and API layer.
Developer Experience: Application developers get a modern, self-documenting API that supports exactly the flexible querying patterns they need. No more requesting new endpoints for slight variations in data requirements.
Simplicity: Everything happens within Microsoft Fabric—no need to set up separate API gateways, manage connections between systems, or maintain complex infrastructure. Create your view, expose it through GraphQL, and you're done.
You've now seen how easy it is to expose Lakehouse data through GraphQL APIs using materialized views. This pattern works for any data in your Lakehouse, whether it's retail data, IoT telemetry, financial transactions, or operational metrics.
Ready to try this with your own data? Here are some resources to get you started:
The possibilities are endless when you combine the analytical power of a Fabric LakeHouse with the flexibility of GraphQL. Give it a try and let us know what you build!
Have questions or want to share what you've built? Submit your feedback to Fabric Ideas. We'd love to hear how you're using API for GraphQL with Materialized Lake Views in your organization.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.