architecture/sql-server.md
Hasura GraphQL Engine is a fast, open-source GraphQL service that:
In this post we summarize how Hasura works with SQL Server as a data source.
Here are a few ways you can easily try Hasura with SQL Server in just a few minutes:
Once you have Hasura running:
<sub>Benchmark suite</sub>
Hasura is powered via dynamic configuration, referred to as “Metadata”.
Once the Hasura service starts running, you can dynamically configure its metadata. This configuration is achieved through using a UI, or using an API call, or using code in a git repo to integrate with your CI/CD pipeline.
The metadata captures connection configuration to upstream data sources, relationships between models, and their authorization policies.Using this, Hasura generates a GraphQL schema and presents a GraphQL API that can be consumed.
Hasura takes incoming GraphQL API calls over HTTP and then compiles that into a T-SQL query, including authorization policies with a predicate push-down.
Because of its compiler-like architecture Hasura can avoid N+1 issues entirely. It can memoize aggressively, and issue the minimal number of hits to upstream data sources.
There are 3 key aspects to this:
Compiling into a SQL query:
JSON aggregation:
Connection pooling:
Hasura generates a GraphQL API on tables and views - with support for stored procedures and functions coming soon. This allows evolution of the underlying data model without affecting the generated GraphQL API.
Users can add authorization rules that restrict access to particular entities (or rows) and their fields (columns). These authorization rules combine properties of the data that is being accessed with properties of the session of an API request.
Hasura can extract session information from JWT claims or from a webhook. This allows Hasura to accept end-user API calls directly and process them securely. Read the docs for more information on how it works.
Here are a few examples of types of authorization rules that can be implemented with Hasura:
Compare data in a table, or across a relationship, to a session variable
# Allow access to a music track if the track's album's artist_id is the current user
role: user
table: tracks
permission: tracks.album.artist_id = session.user_id
# For 'public' scope, allow access only to the id and username fields
role: public
table: profile
permission:
fields: [id, username]
# For the 'private' scope, allow access to all fields, but only if the session user is the owner of that data
role: private
table: profile
permission:
fields: [id, username, email]
rule: profile.id = session.user_id
role: user
table: article
permission:
current_user.profile.plan IN article.allowed_plans
# Role 1
private: user can access their own data, and all fields of that data: [id, email, username]
# Role 2
public: user can access anyone's data, but only id and username
# Role3 = Role1 + Role 2
user: [public, private]
# the user role can now safely be assigned to all logged-in users
Feedback and issues are very welcome!
Reach out to the Hasura team via:
If you'd like to see how Hasura + SQL server can work for your team contact us via our website.
We'll also be diving deeper and talking about updates at the upcoming HasuraCon 🎉
Next up on our roadmap for Hasura + SQL Server:
Please do upvote / subscribe to the issues above to stay updated! We estimate these to be available over incremental releases in July/Aug 2021.