Exposing Lakehouse Materialized Views to applications in minutes with GraphQL APIs in Microsoft Fabric
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.
Why This Combination Matters
Before we dive into the how-to, let’s understand why this matters:
- Materialized Views pre-compute and store query results, dramatically improving query performance for complex analytics.
- GraphQL APIs provide a flexible, self-documenting interface that lets developers request exactly the data they need.
- Microsoft Fabric brings these capabilities together in a unified platform, eliminating the need for complex integrations.
The result? Data engineers can optimize query performance while application developers get fast, intuitive API access—without compromising on either side.
What You’ll Build
In this tutorial, we’ll use the LakeHouse sample Wide World Importers retail dataset to create a practical example. We’ll:
- Set up a Lakehouse with sample retail data.
- Create a materialized view that aggregates sales metrics.
- Expose that view through a GraphQL API.
- Query the data using GraphQL.
Let’s get started!
Step 1: Create a Lakehouse with LakeHouse Schemas Enabled
First, we need to create a Lakehouse with schema support enabled. This must be done during the lakehouse creation process.
- Navigate to your Fabric workspace.
- Select + New and select Lakehouse.
- Give your Lakehouse a meaningful name (e.g., ‘RetailAnalytics’).
- Important: Check the box next to ‘Lakehouse schemas (Preview)‘ to enable schema support.
- Select Create.
Now let’s populate it with sample data:
- Select Start with sample data.
- Choose Retail Data Model from Wide World Importers.
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.
Step 2: Create a Materialized Lake View
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 your Lakehouse, select Manage materialized lake views from the ribbon.
- Select new materialized lake view, then new notebook.
- A new notebook opens where you can write your Spark SQL code.
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;
- Run the cell to create the materialized lake view.
- Open the Lakehouse explorer to verify the view was created successfully.
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.

Step 3: Schedule and Monitor Refreshes
One of the powerful features of materialized lake views is the automatic lineage tracking and refresh scheduling.
- Navigate back to your Lakehouse.
- Select Manage materialized lake views to see the auto-generated lineage diagram.
- The lineage view shows dependencies between your view and source tables.
- Select Schedule from the navigation ribbon.
- Turn On the refresh and configure your desired schedule (hourly, daily, etc.).
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.
Step 4: Create an API for GraphQL
Here’s where the magic happens—we’ll expose our materialized lake view through a GraphQL API with just a few clicks.
- In your Fabric workspace, select + New and select API for GraphQL.
- Give your API a descriptive name (e.g., ‘RetailDataAPI’).
- In the API editor, select, Select data source.
- Choose your Lakehouse as the data source.
- Select the SalesByStockItemAndCity materialized lake view from the available tables and views. If you cannot see the view listed in this screen, you might have to access the LakeHouse SQL Analytics Endpoint and manually refresh the available tables and views.
- Select Load to generate the GraphQL schema automatically.
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.
Step 5: Query Your Data with GraphQL
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.

The Power of This Approach
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.
What’s Next?
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:
- Get started with API for GraphQL: Microsoft Fabric GraphQL Documentation.
- Learn about Materialized Lake Views: Materialized Views Guide.
- Explore the Retail Dataset: Try creating different materialized views—customer lifetime value, product performance trends, or seasonal sales patterns.
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.