How to get Graph QL endpoints with Data API Builder

Microsoft Developer · Intermediate ·🔧 Backend Engineering ·2y ago
Skills: API Design85%

Key Takeaways

Create Graph QL endpoints with Data API Builder

Full Transcript

in this episode of open at Microsoft I have Jerry with me to talk about graph and dab stay [Music] tuned hey Jerry very happy to have you for the third time uh on this show so we already spoke about data API Builder to scaffold rest API we saw how it was easy to deploy in the Azure esthetic web app what do you have for us today well one of the things that dab does great is it takes your data Bas like MySQL postgress Cosmos DB and of course Microsoft SQL and we expose it as a rest in point but we also expose it as a graph endpoint and today I just wanted to walk you through I don't know if you've ever seen graphql a lot of people kind of um accidentally associate it with the Microsoft graph which is the great way to you know go through everything in Microsoft 365 we call it a graph but that's not graphql graphql is the language to be able to interact with your data a little bit like well it's a little bit like nothing you've ever seen before it was invented a long time ago by Facebook and it's just one of the coolest things and if you try to inter that try to create your own man there is a lot of work to build your own graph endpoint but that's the beauty of dab dab creates it right there for you I mean it's it's enough work to create a rest in point and to know that dab creates all of those for you it's another to know that you also for free get graphql so uh as a reminder data API Builder is completely open source this is the repository where we are and uh we welcome contributions so we have a thriving Community already with a lot of lot of developers engaged so I welcome you to come put a walk through some of the poll requests look through the code uh contribute as much as you want we uh we definitely welcome that so I did uh make a comment or something like that and the response was pretty quick I think the next day I had like some comments and the fix was already in the the pipeline to be released yeah and I saw your PR that you submitted with all the white space added noid um but nonetheless I mean dab is the one of the coolest things so it runs in a container so it means you can deploy it anywhere it's not a Windows thing it's not it's totally crossplatform uh behind the scenes uh it's written in.net but of course who cares what your API is written in you just want to interact with the endpoints but it's cool to know and to implement uh the graph functionality we use hot chocolate and so it's got the best of the best all the way through and so it's really beautiful however all that being said I want to show you what it's like to to use a graph endpoint and I want to start with the database so I have a simple uh diagram here of uh let me pull it up here there you go of just really simple this is my Star Trek database it has all the characters and all of the series and it has what species those characters are as well so nothing really terrific as far as like the most complicated schema of all time but it is beautiful because it's so simple right and it has these many to manyi relationships because a character can be more than one species and a species can have many characters that represent it as well so to be able to show all of that inside and and think about how difficult that would be with rest so if you just had just something very simple like category and item and you were calling a rest endpoint you could call the category endpoint get the list and then Loop through each of the categor and for each one you would call the item endpoint and get the items for that category if you had five categories let's say that's at least one call to get all the categories and then five more calls to get each of the items for each so that's potentially six now you can do it you can change your rest API to be very specific for your use case to make it so you could just use one but if you have a generic rest API kind of scheme then that's what it is six calls to get the data you need for a single screen on your UI that's what is trying to be solved by a graphql where I can say here's basically all of the items I need in a single query bring them all to me and let it be dynamic and so it's really really beautiful so let's just start if if I'm running a dab here so data API Builder so if I'm running datp I automatically get uh a Swagger endpoint which is how I interact with all of the the rest in points but I also get a banana cake pop end point as well now these are only that's what it's called right that's the Swagger for graph Q I didn't know it's adorable yeah it's adorable but it's also awesome like all of the things that you can do really are kind of magical and so let me show you in this first box is where you construct the query so it's different you don't start by I only want the items you don't start by you start by creating the query and from the query you say what you want inside it and so it has autocomplete as well to help you out and so I I'll start with the series so so uh here's the just the series and everything is kind of a Json format even though it's not Json behind the scenes and can I just stop you because you say there's like a completion is it about like the like the Json or about the the schema because it knows your so glad you asked that's 100% right so when I say dab start and and dab starts for the very first time the way that I make dab work in the first place is just a single configuration file into Json file that describes the tables that I want but if I want graph so in fact let me show you what my configuration file why it's special so I have in my entities right this is the entire um this is the entire configuration file right so I have some runtime information that enables graph I don't have to have it if I don't want it enables rest again I don't have to have it if I don't want it and a couple of other things right including my connection string but then I go into my entities and the things that I want so in the rest world when I say I want an actor that's an actor endpoint where I get all the actors from it and I can filter and I can sort and things like that too yeah but when it comes to the graph world it's a little bit different now I can go down and I can add let me see if I can find one right here so this I I'm passed up uh actor now I'm in the character entity just so you can see but I can add a relationship and I can create a relationship so in this case a character is in a series and so now this is the name of the relationship of the series and can see it's a many to mini relationship that allows me to go in identify which one I'm attaching to which entity I'm attaching to inside the same configuration file and then which files are the connections so remember for many to many it's not a primary key foreign key relationship there's an in between table that allows you to have that mini to mini relationship in a database and so if I were to jump back real quick to let me go to the there we go right so a character and a species in order to get the charact I have to have this cross reference table of character species just like I have to have an actor has a to a series right so uh let me jump here we go so now that I've had that ident uh relationship configured in the in the Json file when I start dab it reads that Json file and automatically creates the schema that is specific to graph oh lovely okay that that's the way graph works and so you get this extra couple of milliseconds in the startup time but as a result it's gone and interrogated your actual database and created all of the relationships for you and presented a schema so if I went over here to schema reference I can see all the different pieces that are okay yeah that's cool so like here's the character here's the series but when I go into the operation I can create a query and the autocomplete is coming from this schema reference that's exposed by data API Builder oh that's awesome yeah so now so there's two ways of of using um there's two ways of using graph just like there are two ways of using rest one is to get data and another one is to send or update or create data I'll talk about that in just a second let's start with just getting data so I create this query and inside the query it's the item that I want and so the reason it knows series is because that's part of the schema right and I've I've represented that in the configuration file as the series table but that that makes it easier for me so if I didn't want it to be called series if I wanted to be called TV series I could rename it give it some easy name that I like the most so now that I'm returning back now if I run this by the way I'm going to get an error because I haven't asked for any columns so it's different than rest rest I say give me the series and it gives me everything so if a series for example has a thousand columns I get all 1,000 columns which makes the payload of a rest call pretty large and difficult to influence that's not the way it works with graph I can say exactly what columns I want to project here and it's as small as I want it to be so if I only need a sing single column that's all I get and it makes the payload nice and Tiny and it makes your app nice and fast as a result as well so it that that's in items is how you uh determine what the columns are that you're going to return and so I'll get the name uh I believe it is plural yes then I'll get the name so now when I run it it returns a list of all of the Star Trek series all the classic Star Trek series we'll say and um so we could start with that I by the way I could add a second I could say what the ID is and then when I run it I'll get both the ID and the name and this is kind of where it begins because I can start to Nest things together because of the relationships I've defined and I can say okay now I know that I have uh the items from a series now I don't want the items instead what I want is um wait why do series here it is yes now inside items that I was in the wrong section uh here is the characters of that series so now I want it and I don't have to do do the join I don't have to make sure that the relationships are correct that's all defined for me behind the scenes making it so the query that I write in graph is as simple as possible and so now the syntax is exactly the same as if I was interacting with series here now instead though I'm interacting with character so I'll get items for it as well and I'll ask for the names in items so name so this should return a list of all of the series and then all of the characters inside that so let me run that and I'll show you so here you go number uh number one is Jame is well it's Star Trek and then James Kirk there's Spock there's Leonard all the ones you would expect and if I needed say for example the star date that they were born on because this is very valuable information I just go ahead and get it so the nice thing is it you don't have to tell me in advance because I'll optimize my rest API and you'll tell me in advance what your UI looks like oh well I'm going to show first all the series then I'm going to show all the characters and I'm like okay I'll create a rest endpoint that returns exactly the data you need but look how I can do that right here and then let's say your ux designer comes in and says you know what we really need to do is now show what species they are and so if you're going to show what species they are I'm going to have to update my rest in point to be optimized for that new UI but instead I can just go here and I can say species there we go species and I could say items are for it or the columns and I can say what the name is so now when I run it it shows that James Kirk is human and it shows that Spock is both human and Vulcan and so regardless of how my API is built it can it's constantly Dynamic and allows me to kind of change what I need to do to tailor my um to TA tailor my payload for whatever UI I have so it's kind of in the past when we would design an application you would have to do a lot of UI work up front to make it so that you could have an optimized API layer now it's the opposite now I can use graph and I can interact with my data in this constantly Dynamic way and on the back end it's doing a whole bunch of work for me and there's resolvers and all kinds of things that make it so I pull from the right table but I don't need to know that all I need to do is construct a query like this and interact with it so it's really really great there are tons of really terrific pre-built libraries out there to interact with graph in points because it can be kind of tricky to build your own query like this um so you don't have to do it from scratch that's not true again with rest so rest when I'm interacting with a rest inpoint more often than not I'm just calling HTTP client. getet and I'm passing in whatever it is I want from there it's not really a wrapper client I could write my rapper client but there's not really a wrapper client to make it easy that's not the way it is with graphql because graphql is so Dynamic and interactive like this all I need to do is point it to a schema and after I've pointed it to a schema I have a dedicated client that gives me all of the strong typing I would expect in net or just the easy interaction I would want in like python or JavaScript now if you were to build your own this is the this is the deal Frank if you were to build your own every time you had this nested thing you would need to build a resolver on the other end to be able to say this table joins in this way so I only want to get these sorts of things that's pretty nice because if you're only going from you know top level to next to child to Grand child you could build a resolver and as much work as it is if you're paid by the hour it's going to be okay but the thing is once you have these relationships identified the even reverse um relationships where I want to go instead I want to go from the series to the character I want to go from instead the character back to the series and do reverse all of that is built into dab so you get it as long as you've defined it in the config file right very straightforward no resolver needed no all this backend work is there and so we've just in introduced a couple of new features in fact because now we're at 10 so we're still in public preview we'll be released to um GA in March is what we're on track for right now okay and so every time we get these little dot releases we keep adding all these features because we're like we got to get these in before GA because it's going to be spectacular and so the we've got a couple of new ones one of them is multiple data sources so now I can I can provide not only one connection string but several connection strings and as I'm inside my graph query here I could say I want the series and then I want the character and then I want the species and the series could be from one location uh one database Source uh and the character could be from another and the species could be from another and so we don't join across disparate data sources like that but we do allow you to have in a single query I can call to Cosmos DB and get my unstructured data I could call it a SQL get my structured data and then I could call to my on-prem database and get some sort of internal data as well all inside a single query that comes back as a single block we have to uh have you back to show us like a demo it's unbelievable and uh but but it's just one of those things that we can enable with a graph query because graph just it's like however you want to Define it is how it's going to work and we just spin it up and it's crazy to me how it takes just a couple of milliseconds it and dab is suddenly just up and running and you have all of these pieces all the developer tools you need caching and securities built in of course we would never skip those pieces and so it's really cool stuff Frank so we'll make sure to put provide all the links in the description for people to get started with uh the data API Builder or dab uh and thank you again Jer for being with us sharing that beauty of dab and we'll make sure to invite you again on the show to talk about this cross database data sour I love it thanks Frank I appreciate it

Original Description

Unleash the potential of your databases with Data API Builder, a tool that effortlessly creates Graph QL endpoints, enabling advanced and efficient data interactions. This no-code solution streamlines the development of flexible and high-performance APIs, saving time and effort while focusing on innovative Graph QL capabilities for dynamic application development. Chapters: 00:00 - Introduction 00:40 - Graph or GraphQL 02:38 - Star Trek demo Resources: Find the latest info about the open-source Data API Builder project available at: https://github.com/Azure/data-api-builder Try it yourself: https://aka.ms/dab/swa 📌 Let's connect: Frank | https://x.com/fboucheros Jerry | https://x.com/jerrynixon Subscribe to the Open at Microsoft: https://aka.ms/OpenAtMicrosoft Open at Microsoft Playlist: https://aka.ms/OpenAtMicrosoftPlaylist New episode every Tuesday!
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Microsoft Developer · Microsoft Developer · 0 of 60

← Previous Next →
1 Prepare for the DP-300 exam & the Azure Database Administrator Associate cert | Data Exposed
Prepare for the DP-300 exam & the Azure Database Administrator Associate cert | Data Exposed
Microsoft Developer
2 What I Wish I Knew ... about landing a job in tech
What I Wish I Knew ... about landing a job in tech
Microsoft Developer
3 Igniting Developer Innovation with Vector Search
Igniting Developer Innovation with Vector Search
Microsoft Developer
4 Combining the power of vector search with Azure OpenAI then revolutionize image search with vectors!
Combining the power of vector search with Azure OpenAI then revolutionize image search with vectors!
Microsoft Developer
5 What I Wish I Knew ... about finding your place in tech
What I Wish I Knew ... about finding your place in tech
Microsoft Developer
6 Fluent UI React Insights: Accessible by default
Fluent UI React Insights: Accessible by default
Microsoft Developer
7 Signing Container Images with Notary Project
Signing Container Images with Notary Project
Microsoft Developer
8 What I Wish I Knew ... about finding your place in tech
What I Wish I Knew ... about finding your place in tech
Microsoft Developer
9 What programming languages does GitHub Copilot support?
What programming languages does GitHub Copilot support?
Microsoft Developer
10 What I Wish I Knew ... about how much your job can change
What I Wish I Knew ... about how much your job can change
Microsoft Developer
11 What I Wish I Knew ... about how much your job can change
What I Wish I Knew ... about how much your job can change
Microsoft Developer
12 How do I become more confident about AI?
How do I become more confident about AI?
Microsoft Developer
13 How do I become more confident about AI?
How do I become more confident about AI?
Microsoft Developer
14 Performance Demos of SQL’s Intelligent Query Processing Feedback capabilities | Data Exposed
Performance Demos of SQL’s Intelligent Query Processing Feedback capabilities | Data Exposed
Microsoft Developer
15 What I Wish I Knew ... about coming to Microsoft
What I Wish I Knew ... about coming to Microsoft
Microsoft Developer
16 What I Wish I Knew ... about coming to Microsoft
What I Wish I Knew ... about coming to Microsoft
Microsoft Developer
17 Revolutionizing Image Search with Vectors
Revolutionizing Image Search with Vectors
Microsoft Developer
18 Igniting developer innovation with Vector search and Azure OpenAI
Igniting developer innovation with Vector search and Azure OpenAI
Microsoft Developer
19 Getting Started with Azure AI Studio's Prompt Flow - Part 2
Getting Started with Azure AI Studio's Prompt Flow - Part 2
Microsoft Developer
20 What I Wish I Knew ... about finding my career path
What I Wish I Knew ... about finding my career path
Microsoft Developer
21 What I Wish I Knew ... about finding my career path
What I Wish I Knew ... about finding my career path
Microsoft Developer
22 Windows Terminal's journey to Open Source
Windows Terminal's journey to Open Source
Microsoft Developer
23 Can I trust the code that GitHub Copilot generates?
Can I trust the code that GitHub Copilot generates?
Microsoft Developer
24 What I Wish I Knew ... about interviewing
What I Wish I Knew ... about interviewing
Microsoft Developer
25 What I Wish I Knew ... about interviewing
What I Wish I Knew ... about interviewing
Microsoft Developer
26 What is the Microsoft TechSpark Program?
What is the Microsoft TechSpark Program?
Microsoft Developer
27 SQL Server 2022: Accelerate query performance while reducing query compile time - w/ no code changes
SQL Server 2022: Accelerate query performance while reducing query compile time - w/ no code changes
Microsoft Developer
28 What I Wish I Knew ... about discovering computer science
What I Wish I Knew ... about discovering computer science
Microsoft Developer
29 What I Wish I Knew ... about discovering computer science
What I Wish I Knew ... about discovering computer science
Microsoft Developer
30 Call center transcription and analysis using Azure AI
Call center transcription and analysis using Azure AI
Microsoft Developer
31 How to use Text Analytics for health in Azure AI Language
How to use Text Analytics for health in Azure AI Language
Microsoft Developer
32 Azure OpenAI-powered summarization in Azure AI Language
Azure OpenAI-powered summarization in Azure AI Language
Microsoft Developer
33 Accelerate data labeling using Azure OpenAI and Azure AI Language
Accelerate data labeling using Azure OpenAI and Azure AI Language
Microsoft Developer
34 Building a Private ChatGPT with Azure OpenAI
Building a Private ChatGPT with Azure OpenAI
Microsoft Developer
35 What I Wish I Knew ... about how to interview
What I Wish I Knew ... about how to interview
Microsoft Developer
36 What I Wish I Knew ... about how to interview
What I Wish I Knew ... about how to interview
Microsoft Developer
37 Getting Started with Azure AI Studio's Prompt Flow - Part 3
Getting Started with Azure AI Studio's Prompt Flow - Part 3
Microsoft Developer
38 Intelligent Apps with Azure Kubernetes Service (AKS)
Intelligent Apps with Azure Kubernetes Service (AKS)
Microsoft Developer
39 Getting Started with Azure Blob Storage | Data Exposed: MVP Edition
Getting Started with Azure Blob Storage | Data Exposed: MVP Edition
Microsoft Developer
40 Chat + Your Data + Plugins
Chat + Your Data + Plugins
Microsoft Developer
41 What I Wish I Knew ... about different career paths
What I Wish I Knew ... about different career paths
Microsoft Developer
42 What I Wish I Knew ... about different career paths
What I Wish I Knew ... about different career paths
Microsoft Developer
43 Advanced Dev Tunnels Features | OD122
Advanced Dev Tunnels Features | OD122
Microsoft Developer
44 Learn Live - Manage performance and availability in Azure Cosmos DB for PostgreSQL
Learn Live - Manage performance and availability in Azure Cosmos DB for PostgreSQL
Microsoft Developer
45 Plan your SQL Migration to Azure with confidence | Data Exposed
Plan your SQL Migration to Azure with confidence | Data Exposed
Microsoft Developer
46 What I Wish I Knew ... about social skills in a tech career
What I Wish I Knew ... about social skills in a tech career
Microsoft Developer
47 What I Wish I Knew ... about social skills in a tech career
What I Wish I Knew ... about social skills in a tech career
Microsoft Developer
48 All About Vectors, Search, and Function Calling in Azure OpenAI - Labor Day Special
All About Vectors, Search, and Function Calling in Azure OpenAI - Labor Day Special
Microsoft Developer
49 Introduction to project ORAS
Introduction to project ORAS
Microsoft Developer
50 What I Wish I Knew ... about finding the right major
What I Wish I Knew ... about finding the right major
Microsoft Developer
51 What I Wish I Knew ... about finding the right major
What I Wish I Knew ... about finding the right major
Microsoft Developer
52 What I Wish I Knew ... about how to approach programming
What I Wish I Knew ... about how to approach programming
Microsoft Developer
53 What I Wish I Knew ... about how to approach programming
What I Wish I Knew ... about how to approach programming
Microsoft Developer
54 Learn Live - Scale from a single node to multiple nodes with Azure Cosmos DB for PostgreSQL
Learn Live - Scale from a single node to multiple nodes with Azure Cosmos DB for PostgreSQL
Microsoft Developer
55 What I Wish I Knew ... about diversity in tech #1
What I Wish I Knew ... about diversity in tech #1
Microsoft Developer
56 What I Wish I Knew ... about diversity in tech #1
What I Wish I Knew ... about diversity in tech #1
Microsoft Developer
57 Get started with SQL Server AGs across Windows, Linux and Container Replicas | Data Exposed
Get started with SQL Server AGs across Windows, Linux and Container Replicas | Data Exposed
Microsoft Developer
58 Writing LLM Apps with Azure AI and PromptFlow
Writing LLM Apps with Azure AI and PromptFlow
Microsoft Developer
59 What I Wish I Knew ... about how cool working in tech could be
What I Wish I Knew ... about how cool working in tech could be
Microsoft Developer
60 Open Source foundation models in Azure Machine Learning & optimization techniques behind the scenes
Open Source foundation models in Azure Machine Learning & optimization techniques behind the scenes
Microsoft Developer

Related Reads

📰
What Is a Simple Request and When Does the Browser Send a Preflight Request?
Learn when browsers send preflight requests and how to handle them in your web development workflow
Dev.to · Alireza Hassankhani
📰
How to learn the basics of c++?
Learn C++ basics in a month with free resources and a solid study plan
Reddit r/learnprogramming
📰
Composer Isn’t Just a Dependency Manager — It’s the Backbone of Modern PHP Development
Learn how Composer is the backbone of modern PHP development and why it's more than just a dependency manager
Medium · Programming
📰
How a frustrating school project led me to build my first CLI tool.
Learn how a frustrating school project inspired the creation of a first CLI tool and discover the process of building a command-line interface using JavaScript
Medium · JavaScript

Chapters (3)

Introduction
0:40 Graph or GraphQL
2:38 Star Trek demo
Up next
Indian Express Editorial Analysis by Chandan Sharma - 1 JULY 2026 | UPSC Current Affairs 2026
StudyIQ IAS
Watch →