Skip to main content
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Get Fabric certified for FREE! Don't miss your chance! Learn more

rajendraongole1

GraphQL Explained: Transforming Data Access in Microsoft Fabric

GraphQL:

GraphQL is a query language for your API and a server-side runtime for executing those queries. It was developed by Facebook and open-sourced in 2015.

The key distinction is that, unlike REST, where the server dictates the data structure sent from fixed endpoints, GraphQL puts the power in the clientโ€™s hands. The client specifies exactly the data (fields, objects, relationships) it needs, and the server responds with a JSON object that perfectly matches that structure. Image Reference from MS Learn

1.png

Importance and Why It Is Required

Why do we need yet another way to communicate with data? The necessity of GraphQL stems from the pain points of traditional data access:

  1. Eliminating Over-Fetching (The Necessity): In a REST API, an endpoint /users/1 might return 20 fields, even if your application only needs the user's name and email. This wastes bandwidth, increases latency, and puts unnecessary load on the network and server. GraphQL solves this by allowing the client to request only name and email.
  2. Addressing Under-Fetching (The Requirement): To build a user profile page, a REST architecture might require:GraphQL lets you fetch all this related data in a single, unified request by traversing the relationships defined in the schema, simplifying the client-side code dramatically.
  3. GET /users/1
    GET /users/1/orders
    GET /users/1/addresses

Where Will We Use GraphQL

GraphQL is ideal for any application where client performance, network efficiency, and flexible data requirements are critical. This is particularly true in the following areas:

 

Scenario with General Example:

Microsoft Fabric API for GraphQL is a data access layer that allows for quick and effective querying of numerous data sources using a widely used and well-known API technology. The API enables you to abstract the intricacies of backend data sources, allowing you to focus on your application's logic while providing all of the data a client needs in a single call. GraphQL employs a simple query language and easily manipulatable result sets, reducing the time it takes for applications to access your data in Fabric.

Create a workspace: create a workspace with Fabric enabled. Workspace name: FabricWorksp

2.png

Now, Let's create a SQL Database with sample data

3.png

 

I have given a name ADWDB ad DB name

4.png

 

Same as with Lakehouse, with data warehousing we can see the ADWDB explorer as below: Once you have created your database, you can load sample data into your database from the sample data card.

5.png

Choosing sample data for testing purpose:

6.png

Now, the database will be populated with sample data for the AdventureWorks scenario.

Query SQL database:

The SQL query editor supports IntelliSense, code completion, syntax highlighting, client-side parsing, and validation. You can execute DDL, DML, and DCL statements.

SELECT

     p.Name AS ProductName,

     pc.Name AS CategoryName,

     p.ListPrice

 FROM

     SalesLT.Product p

 INNER JOIN

     SalesLT.ProductCategory pc ON p.ProductCategoryID = pc.ProductCategoryID

 ORDER BY

 p.ListPrice DESC;

 

This query joins the product and product category tables to display the product names, their categories, and their list prices, sorted by price in descending order.

Now, let's create an API for GraphQL: go back to the workspace and select the New Item and choose API for GraphQL

7.png

Below indetailed steps i have posted as per sequence:

  1. If prompted to select a connectivity option, select Connect to Fabric data sources using single sign-on (SSO) authentication.
  2. On the Choose the Data You Want to Connect page, select the previously created ADWDB database.
  3. Select Connect.
  4. On the Choose Data screen, pick SalesLT.Product table.
  5. Preview the data and then pick Load.
  6. Select Copy endpoint and take note of the public URL link. We do not require this, however that is where you would go to copy your API address.

    8.png

    Select DB:

    9.png

    Query data using GraphQL

    Copy Endpoint:

    10.png

    https://e8dbcd73d60b45958b34f50f9a9bf274.ze8.graphql.fabric.microsoft.com/v1/workspaces/e8dbcd73-d60...

    11.png

     

    Now that our API is created, we only want to expose the sales data for reading operations in this sc...

    1. On the Schema explorer of your API for GraphQL, expand Mutations.
  7. Select on the โ€ฆ (ellipsis) next to each mutation and select Disable.

    This will prevent any modifications or updates to the data through the API. This means that the data will be read-only, and users will only be able to view or query the data, but not make any changes to it.

    letโ€™s query the data using GraphQL to find all the products whose names begin with โ€œHL Road Frame.โ€

    Disable mutations

    14.png

    Disabled: hover on the top ... ellipse and disabled option is there

    I have disabled create, update and delete on product

    Execute the query on pasted

     letโ€™s query the data using GraphQL to find all the products whose names begin with โ€œHL Road Frame.

    only it gets displaced in the result set beginning with โ€œHL Road Frame.โ€

    15.png

    similarly i have fetched one more table Product category:

    16.png

    Build the data model as well via fetched tables:

    17.png

     

    As with modeling, you can see the relationship view as follows:

    19.png

    Conclusion

    The Microsoft Fabric API for GraphQL is more than just a developer toolโ€”itโ€™s a philosophy shift in how we access our consolidated data assets. It directly addresses the shortcomings of traditional APIs by giving consumers the power to define their data needs.

    By leveraging GraphQL, you can transform your Fabric data into a highly efficient, performant, and flexible service layer, enabling you to build responsive, modern applications that consume data intelligently. I highly recommend exploring this feature in your own Fabric environment to experience the difference firsthand!

                                                                                      Happy Reading!

Comments