- Hasura was founded in July, 2017.
- its unicorn: click here
- What is Hasura? | source: click here | 20 JANUARY, 2020 | 3 MIN READ: The Hasura GraphQL Engine is a blazing-fast GraphQL server that gives you instant, realtime GraphQL APIs over Postgres, with webhook triggers on database events, and remote schemas for business logic. Hasura helps you build GraphQL apps backed by Postgres or incrementally move to GraphQL for existing applications using Postgres. The Hasura GraphQL Engine is open-source. You can check out the complete repo here.
- About Hasura Company and Team: click here
- Tanmai Gopal (co-founder) | Linkedin | Blogs
- Rajoshi Ghosh(co-founder) | Linkedin
- watch what is hasura from Tanmai Gopal - click here
- Who is using Hasura? case studies - click here, other companies
- Getting started with hasura locally - Docs: click here
- Getting started with hasura locally - Docs: click here
- Start Locally with docker: Click here
- Fireshipio - Hasura: Click here
- Hasura - Getting Started (Your First Query) @youtube: Click here
// SAMPLE GRAPHQL QUERY VIA FETCH, made by code exporter in Hasura. ~Sahil
/*
This is an example snippet - you should consider tailoring it
to your service.
*/
async function fetchGraphQL(operationsDoc, operationName, variables) {
const result = await fetch(
"undefined",
{
method: "POST",
body: JSON.stringify({
query: operationsDoc,
variables: variables,
operationName: operationName
})
}
);
return await result.json();
}
const operationsDoc = `
mutation MyMutation($likes: Int = 2) {
insert_blogs(objects: {title: "awsm blog", year: 2022, url: "google.com", likes: $likes}) {
affected_rows
returning {
author
id
likes
title
updated_at
url
year
user_id
created_at
}
}
}
`;
function executeMyMutation(likes) {
return fetchGraphQL(
operationsDoc,
"MyMutation",
{"likes": likes}
);
}
async function startExecuteMyMutation(likes) {
const { errors, data } = await executeMyMutation(likes);
if (errors) {
// handle those errors like a pro
console.error(errors);
}
// do something great with this precious data
console.log(data);
}
startExecuteMyMutation(likes);
Awesome: Source: Hasura Authorization #EasyGraphQLwHasura, all this in blogpost: Click here.
- Add Table:
- Add foreign key like that:
- Add this relationship:
- We are going to use deafult
employees
text there: - Add the object relationship as well (This is Manager Relation):
- Add another table and save the table:
- Now Add foreign key like that:
- We can (but we don't) add relation like we added earlier as shwon in there but we'll use
Track
way to add relationship this time(see next screenshot): - Click on
Track All
to track all realtions automatically: - We can see that relationship is set successfully between payroll and employee:
- Lest make
manager_id
field as nullable: - Lets add employees now:
We can see that Janet and Michael are added:
Now we use Michael's id
as highlighed in above screenshot to be as manager_id
for filed of Elanor and Chiddi:
We can see the results as expected:
- Lets create payroll entries:
Now in payroll we can see all the entries:
-
Querying in graphiql we can see such data which says Michael is manager for Elanor and Chidi:
-
We can see employees for employees i.e., for Michael we can see he has employees as Elanor and Chidi:
-
Setting up permission for HR (insert* permission) and save that:
-
Now we clone the permission for select, update and delete as well by doing that:
-
We can see that HR now has all the permissions for insert, select, update and delete:
-
Now we set select permission for the employee who is actually a Manager:
-
Lets clone select permission of Employees(i.e., same above permision) for HR and Managers as well (FYI: Do overwrite the permissions if asked):
Now we can see that everyone can select:
BUT for now we are just gonna do it like this for demo (role=HR and id=Jane's Id):
and we see that HR can select the data.
also, if we put role=Manager and id=Michael's Id we see that Michael can select data for Elanor and Chidi only:
and Elanor can only select her own data only:
Also we can see that employee can not mutate data bcoz we set that in permission roles that employees can only query data:
And if we use Manager role instead we can see that Manage can mutate and insert data as well:
Changing salary of Elanor by Manager:
Lets see Elanor's Salary (we can move to payroll table for any employee like that):
and we can see it update correctly (we can use that button to close it though):
Also, if we try to update Janet's salary by using Manager role we see that its not allowed: