>> Learn how to use a Hasura GraphQL Engine with
Azure SQL Database this week on Data Exposed.
[MUSIC]
>> Hi, I'm Anna Hoffman and welcome
to this episode of Data Exposed.
Today, I'm joined by Abby from Hasura.
Abby, thanks so much for joining us on the show today.
Can you tell us a little bit about what you do in Hasura.
>> Hi, Anna, thanks for having me.
My name's Abby, I work here as
a Software Engineer on the Data Sources team.
Our team's responsible for enabling and adding support for
new data sources such as Azure SQL Server.
>> Awesome. Cool. We're excited to have you on
the show and using Hasura
and GraphQL as your SQL isn't something I know a ton about,
so I'd love to just pass it to you.
I know you have some stuff prepared to share with us.
How do these things work together and how is Hasura making it
easier to work with things like Azure SQL database?
>> Sure. Absolutely. Just a brief intro to Hasura.
Hasura GraphQL engine is a fast open source GraphQL service that
gives you instant real time GraphQL APIs on top
of a variety of data sources.
Originally that was Postgres and though more
recently we started supporting SQL Server,
BigQuery, Citus and many more to come.
It gives you real time GraphQL API as well
as built in row and column level authorization.
Today, I'll be demoing just how quick and easy it is to connect to
a new or existing Azure SQL database,
run a series of GraphQL queries against it,
and then customize permissions for
more granular row and column level access control.
If it's okay, I'll go ahead and share my screen.
Fantastic. Thank you.
Just a bit of set up.
What we're looking at here is the GraphQL Engine console,
which is the main admin interface
you'll be presented with when you start working with Hasura.
This is what you might typically use
to build the back end for your application,
connect new data sources as well as exploring queries.
I also have a view app,
just a sample application.
To do this application,
I'll be using to illustrate some of the cool features that
you can use on Hasura.
For this, I've followed some of Azure sample repo steps,
which will be shared I believe after this this demo.
I've created an Azure SQL database,
and the first thing I want to do on
the Azure Console is to connect it.
I'm going to give it a sensible name like sqlserverdb.
I've already got my connection
string behind the environment variable,
which is a Hasura SQL Server URL.
So I'll collect this database
and I can immediately see it show up in my data manager here.
We can ignore this PostgreSQL database for now,
and you can see here I've connected to
my readily set up Microsoft SQL Azure database
here with some default settings.
If we take a look at what's
available just for the purposes of a demo,
I've set up the scheme already,
so I've set up to do list table and I've set up
a user table so that I can demonstrate
some of the permission features.
If I were to, for example,
try and test the GraphQL API straight away,
I'll actually find in this GraphQL API Explorer,
I don't yet have any queries available.
The reason for that is if I go back to the data manager,
I haven't yet tracked these tables,
and so when I click "Track on them" this is the message suggests,
this will expose the list of tables and
views over the GraphQL API.
At the moment I'm just tracking tables,
but you can also track views if you like.
I also have some relationship side also which tracks.
I'm exposing all of these things over the GraphQL API,
such that when I revisit this GraphQL API Explorer,
I now have access to
these queries immediately on the left hand side.
To be honest, that was it. That took all
of two minutes to connect to database, track those tables,
and now we immediately have access
to some GraphQL queries exposed by Hasura.
If, for example, I wanted to
get the current to do list items in my table,
I haven't added anything yet,
as we can see in the application,
the first thing that I wanted to highlight here was
just how quick and easy you can get
started with a GraphQL API.
This already got some suggested queries,
I like this because I don't have to
write any custom queries myself.
I don't even really have to know
any GraphQL and I've got some suggestive queries here,
and so I can "Select" all of the fields I like,
I can "Add" filters and things like that.
I'm really in a point and click basis
if I haven't yet familiarize myself with GraphQL.
If I wanted to, for example,
so this is a simple query which is getting
the items in the To Do List and I can also
run mutations by the same view
and with the same ease of doing this in the UI.
If I wanted to create a To Do,
I can do this all via here.
I didn't need to do this much things,
and I need to return some field on a successful response.
I can run that in the graphical UI,
and that's executed successfully
because I've got the response
and if I navigate to my application,
refresh the page, I'll see that To Do List right in there.
Really what I'm illustrating via this GraphQL,
so this Graphical Explorer,
I've got getTodo,
I've gotten a createTodo mutation
and I'm doing exactly the same thing.
This application is running the same queries
in exactly the same way.
>> This is really cool. I have
one question as someone who is new to this.
From the SQL side,
how can users understand
what SQL queries are generated and sent to the database?
Then if I need to troubleshoot,
how do I do that from here?
>> That's a fantastic question.
In order to see what queries have been generated,
you can actually use the feature,
Analyze, and you can select a query to be analyzed.
You can do this for any queries you
decide to run into in your application.
You can see both the generated SQL
and you can also see the execution plan.
If you're finding particular queries are
slow or you aren't getting exactly the results that you expect,
this would be the place to do it.
You can drill and as deep as you want with
your generated SQL and with your execution plan.
>> Awesome. That's really cool.
>> That was creating new to-dos and giving
them and essentially recording
the same queries here in the application.
I also wanted to show
things that you can illustrate deletions
as well and using the code,
I'm using the Explorer tab here to build my queries.
I wanted to delete then insert another to do
actually before I do it.
I can also do updates and things like that so all of these are
just calling very basic GraphQL queries.
But the idea is that you actually don't even need to know
any background to make immediate use
of this functionality in Hasura.
The other thing I wanted to illustrate
is that this contrived example
gets a little bit tedious because I might have to,
for example, refresh the application.
You can imagine if this is
an app that's accessed by multiple users,
I might want to do something like fetch data as it's updated.
If we have a shared to-do list table or is being accessed
and data is being changed by multiple users,
you might want something like subscriptions
to effectively fetch data whenever it's
updated without having to
refetch it from the client's point of view.
That's something that we can do really easily in Hasura as well,
just by changing this very keyword "Subscription" and running it.
What this does is, we try to be listening for
updates to our data.
We get real-time updates and the nice thing about this is that
Hasura comes with these subscriptions completely out of the box.
You don't have to do anything additional here
again, no manual [inaudible]
What we're seeing here is that this
automatically got updated because we're just
listening for updates so you
can imagine here the utilization that we might get,
getting real-time updates or
data if you have multiple users, for example.
The very final thing that I wanted to share was
the row and column level authorization features.
Now I can close the application, we just close the tab.
I wanted to go to the data and schema management page.
Before I do, some of you might
notice that I have two tables in a schema.
I have a to-do list and I also have a user list.
If I did, want to limit for example,
the permissions on the user's table.
For example, as a user here I can access all other users,
which we might want to restrict for a variety of purposes.
I can do that by Hasura's "Data & Schema management" page
and navigating to the user table
and clicking on the "Permissions".
I can actually introduce a new role
here so I can introduce a user role
with its own row and column level authorization checks.
For example, if I wanted users to be able
to view other user IDs but not their name,
I can apply the "Row select permission",
the users can select any row without any checks,
but limit the "Column select permissions" to
just the user ID so I'm not suddenly exposing any data here.
Then I don't really want the user to be able to do anything else
with any other rows in the user table.
Here, in order to preview that,
what we need to do is update the request header
to introduce both,
role, now to make that user.
I've added a user role in addition to
the admin role and actually that's all I need really.
I don't know if you saw very clearly that actually I've
limited the queries I have to now as a user.
If you wanted to see that little bit there,
I can just toggle this on and off.
You can see as an administrator,
which is the default,
on the GraphQL console I have access to to-do list,
user table, etc.,
and all of the limitations on those tables,
but once I toggle on the "X-Hasura-Role",
I have restricted permissions effectively and you can
customize these permissions however you like.
You can do as many roles as you like
and as complex permissions as you need for your application.
>> Awesome.
>> I think that's about it.
Those are the things I wanted to share.
>> This is really cool Abby.
Thanks so much for coming on the show and sharing this with us.
I am feeling like I really want to get hands on and get started.
Do you have advice for our folks getting started with
Hasura and their Azure SQL databases today?
>> Yes, absolutely so I would say,
first of probably take a look at
the blog post I suppose we'll share after this.
On top of that, Hasura just has
a wealth of documentation about getting started.
You really can get started as simply as
I illustrated there in just a few clicks.
Once you have in as your SQL database set up,
you just go to the data tab and pass in
either the connection stream on its own or a environment variable,
and then you can start accessing
your data and running queries against it almost immediately.
>> Awesome. Well, thanks so much Abby for coming on the show.
To our viewers, we put a bunch of links in
the description so you get started with the tutorial,
review the blog post and let us know what you
think of using GraphQL Hasura with Azure SQL.
Again, thanks for joining us today.
>> Thank you.
>> Give this video a like. Leave us a comment.
Let us know what you think, and we hope to see you
next time on Data Exposed.
[MUSIC]