We've been working hard on a core Hasura feature that will allow you to fetch related data that is in your database and in remote data sources with GraphQL. (Currently in preview, if you'd like to get notified when this is released, do sign up here!)
As developers and teams move to using more and more 3rd party APIs, multiple databases & microservices, data and "the source of truth" is getting spread across these data-sources. Application developers have a hard time getting access to precise slices of data and a lot of dev cycles are spent in bringing all that data together securely.
Remote Joins in Hasura extend the concept of joining data across tables, to being able to join data across tables and remote data sources. Once you create relationships between types from your database and types created from APIs, you can then “join” them by running GraphQL queries. #JoinAllTheThings
Head to the PR to check out more details, read the preview docs, and to try out a test Hasura image that you can spin up. Jump on our discord or comment on github and let us know what you think!
Remote joins can join across the database and APIs. These APIs can be custom GraphQL servers you write, 3rd party SaaS APIs, or even other Hasura instances.
Of course, because Hasura is meant to be a GraphQL server that you can expose directly to your apps, Hasura also handles security and authorization while providing remote joins.
Use Case #1: Customer data joined with Account/Billing/Payment information in Stripe
If you have a payment method on your app that uses Stripe, a lot of account and billing information about your customer resides with Stripe. For example, the customer's saved cards, account balance, billing/invoice history.
On your app, you'd typically want to show users their saved cards and invoice history. You'd write code to fetch the right data from the Stripe API for the right users/invoices and return that as an API response to your app.
This is what this setup looks like on Hasura:
Use-case #2: User data joined with profile information in Auth0
When you use an external authentication provider (or even an authentication/user management microservice that your team doesn't own directly), there will be some information that is only provided by the auth service. For example, last_login
, verified_email
, login_count
and so on.
In your database, you would typically have a user table that has an auth0_id
. To fetch auth specific information, you would need to use this id and the Auth0 API.
Here's how Hasura helps you automate that process:
Use-case #3: Joining data across 2 separate databases
The title says it all 🤓. And here's how this works with Hasura!
Note: Hasura Remote Joins is a type of GraphQL federation, similar to Apollo Federation. The key difference is that Apollo Federation aims to help organisations with multiple GraphQL teams “federate” a global GraphQL schema. Hasura remote joins help you “join” across multiple data-sources (or GraphQL microservices) so that you get a unified GraphQL API. This unified GraphQL API might be required for a team that has multiple sources of data for their application or might be a unified GraphQL API across various teams (like Apollo Federation) maintained by a central data API team in the organisation.
Try it out and let us know what you think! We ❤️ your feedback. Hit us up on our github or on discord. Remote Joins will be out of preview and released very very soon for production use!
This article was originally written and published by Tanmai Gopal on the Hasura blog.
Top comments (0)