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 this post, you learn how to use a stored procedure to register new products, with server-side logic for validation, formatting, and ID generation — all exposed through a GraphQL mutation in Fabric.
CREATE PROCEDURE SalesLT.RegisterProduct @Name nvarchar(50), @ProductNumber nvarchar(25), @StandardCost money, @ListPrice money, @SellStartDate datetime AS BEGIN SET NOCOUNT ON; SET IDENTITY_INSERT SalesLT.Product ON;-- Validate pricing logic IF @ListPrice <= @StandardCost THROW 50005, 'ListPrice must be greater than StandardCost.', 1;
-- Transform product name: capitalize first letter only DECLARE @CleanName nvarchar(50); SET @CleanName = UPPER(LEFT(LTRIM(RTRIM(@Name)), 1)) + LOWER(SUBSTRING(LTRIM(RTRIM(@Name)), 2, 49));
-- Trim and uppercase product number DECLARE @CleanProductNumber nvarchar(25); SET @CleanProductNumber = UPPER(LTRIM(RTRIM(@ProductNumber)));
-- Generate ProductID by incrementing the latest existing ID DECLARE @ProductID int; SELECT @ProductID = ISNULL(MAX(ProductID), 0) + 1 FROM SalesLT.Product;
INSERT INTO SalesLT.Product ( ProductID, Name, ProductNumber, StandardCost, ListPrice, SellStartDate ) OUTPUT inserted.ProductID, inserted.Name, inserted.ProductNumber, inserted.StandardCost, inserted.ListPrice, inserted.SellStartDate VALUES ( @ProductID, @CleanName, @CleanProductNumber, @StandardCost, @ListPrice, @SellStartDate ); END;
DECLARE @RC int DECLARE @Name nvarchar(50) DECLARE @ProductNumber nvarchar(25) DECLARE @StandardCost money DECLARE @ListPrice money DECLARE @SellStartDate datetime-- TODO: Set parameter values here. Set @Name = 'test product' Set @ProductNumber = 'tst-0012' Set @StandardCost = '10.00' Set @ListPrice = '9.00' Set @SellStartDate = '2025-05-01T00:00:00Z'
EXECUTE @RC = [SalesLT].[RegisterProduct] @Name ,@ProductNumber ,@StandardCost ,@ListPrice ,@SellStartDate GO
Next select the SalesLT tables in your database and the stored procedure we just created, then click Load:
Get_data_screen_to_select_tables_and_procedures_in_API_for_GraphQL
The GraphQL API, schema and all resolvers are automatically generated in seconds based on the SQL tables and stored procedure.
mutation {
executeRegisterProduct (
Name: " graphQL swag ",
ProductNumber: "gql-swag-001",
StandardCost: 10.0,
ListPrice: 15.0,
SellStartDate: "2025-05-01T00:00:00Z"
) {
ProductID
Name
ProductNumber
StandardCost
ListPrice
SellStartDate
}
}
Tips
✅ Microsoft Fabric API for GraphQL
✅ Microsoft Fabric SQL database
✅ Stored procedures for business logic
This gives you the power to define robust, consistent rules in SQL for your data — and access it cleanly via GraphQL.
🔗 Resources
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.