<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: harshamadhavan</title>
    <description>The latest articles on DEV Community by harshamadhavan (@harshamadhavan).</description>
    <link>https://dev.to/harshamadhavan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F196663%2F85902f61-b3cc-4907-b74b-b6c84c5f8d6c.png</url>
      <title>DEV Community: harshamadhavan</title>
      <link>https://dev.to/harshamadhavan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/harshamadhavan"/>
    <language>en</language>
    <item>
      <title>Remote Joins: A GraphQL API to join across your database and other data-sources</title>
      <dc:creator>harshamadhavan</dc:creator>
      <pubDate>Fri, 26 Jul 2019 09:23:54 +0000</pubDate>
      <link>https://dev.to/hasurahq/remote-joins-a-graphql-api-to-join-across-your-database-and-other-data-sources-43b0</link>
      <guid>https://dev.to/hasurahq/remote-joins-a-graphql-api-to-join-across-your-database-and-other-data-sources-43b0</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Feojjuif7x24wv408azoc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Feojjuif7x24wv408azoc.png"&gt;&lt;/a&gt;&lt;br&gt;Remote Joins: A GraphQL API to join across your database and other data-sources
 &lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://hasura.io/remote-joins" rel="noopener noreferrer"&gt;here&lt;/a&gt;!)&lt;/p&gt;

&lt;p&gt;As developers and teams move to using more and more 3rd party APIs, multiple databases &amp;amp; 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.&lt;/p&gt;

&lt;p&gt;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&lt;/p&gt;

&lt;p&gt;Head to &lt;a href="https://github.com/hasura/graphql-engine/pull/2392" rel="noopener noreferrer"&gt;the PR&lt;/a&gt; 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 &lt;a href="https://discordapp.com/invite/hasura" rel="noopener noreferrer"&gt;discord&lt;/a&gt; or comment on &lt;a href="https://github.com/hasura/graphql-engine" rel="noopener noreferrer"&gt;github&lt;/a&gt; and let us know what you think!&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;




&lt;h2&gt;Use Case #1: Customer data joined with Account/Billing/Payment information in Stripe&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwzrqxwtefi93sn2xceeq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwzrqxwtefi93sn2xceeq.png"&gt;&lt;/a&gt;&lt;/p&gt;
Customer data joined with account, billing, payment-transaction data in Stripe



&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;This is what this setup looks like on Hasura:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Step 1: Setup &lt;a href="https://www.onegraph.com/" rel="noopener noreferrer"&gt;OneGraph&lt;/a&gt; to connect to your Stripe account&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvbd8fax3oos86vviamqn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvbd8fax3oos86vviamqn.png"&gt;&lt;/a&gt;&lt;/p&gt;
Setup OneGraph to connect to your Stripe account



&lt;p&gt;&lt;b&gt;Step 2: Add OneGraph as a remote schema to Hasura&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fosqnwcz61slc0l2hipea.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fosqnwcz61slc0l2hipea.png"&gt;&lt;/a&gt;&lt;/p&gt;
Add OneGraph as a remote schema to Hasura



&lt;p&gt;&lt;b&gt;Step 3: Setup a remote relationship from your customer table to the Stripe resolver using the &lt;code&gt;stripe_customer_id&lt;/code&gt; as the "join" key&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fivkecou95hfijsm84wsu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fivkecou95hfijsm84wsu.png"&gt;&lt;/a&gt;&lt;/p&gt;
Your table should have the stripe_customer_id column



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqtcnkew2w3x7b14g6kdw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqtcnkew2w3x7b14g6kdw.png"&gt;&lt;/a&gt;&lt;/p&gt;
Setup a remote relationship from your customer table to the Stripe resolver using the stripe_customer_id as the "join" key



&lt;p&gt;&lt;b&gt;Step 4: Make GraphQL queries to fetch customer and stripe information in one shot!&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhzuulvy137illv09k31u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhzuulvy137illv09k31u.png"&gt;&lt;/a&gt;&lt;/p&gt;
Make GraphQL queries to fetch customer and stripe information in one shot!






&lt;h2&gt;Use-case #2: User data joined with profile information in Auth0&lt;/h2&gt;

&lt;p&gt;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, &lt;code&gt;last_login&lt;/code&gt;, &lt;code&gt;verified_email&lt;/code&gt;, &lt;code&gt;login_count&lt;/code&gt; and so on.&lt;/p&gt;

&lt;p&gt;In your database, you would typically have a user table that has an &lt;code&gt;auth0_id&lt;/code&gt;. To fetch auth specific information, you would need to use this id and the Auth0 API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnrv4ckecyf0um7effj6x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnrv4ckecyf0um7effj6x.png"&gt;&lt;/a&gt;&lt;/p&gt;
User data joined with account/profile/auth information in Auth0



&lt;p&gt;Here's how Hasura helps you automate that process:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Step 1: Write a serverless function that wraps the Auth0 profile API in a GraphQL query resolver.&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdvcao1jz4a3qudmq3wb7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdvcao1jz4a3qudmq3wb7.png"&gt;&lt;/a&gt;&lt;/p&gt;
Write a serverless function that wraps the Auth0 profile API in a GraphQL query resolver. 



&lt;p&gt;&lt;b&gt;Step 2: Connect this as a remote schema in Hasura&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fue4p4y8gexh8p7a92w8y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fue4p4y8gexh8p7a92w8y.png"&gt;&lt;/a&gt;&lt;/p&gt;
Connect this as a remote schema in Hasura



&lt;p&gt;&lt;b&gt;Step 3: Go to the User table on Hasura and add a "remote relationship" to the schema you added above&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Flnacxrbyp0kj73w9q9j2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Flnacxrbyp0kj73w9q9j2.png"&gt;&lt;/a&gt;&lt;/p&gt;
The auth0_id identifier is the "join" key from your database



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgi0zrmmumst5b0szwuna.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgi0zrmmumst5b0szwuna.png"&gt;&lt;/a&gt;&lt;/p&gt;
Add a "remote relationship" to the auth0 schema



&lt;p&gt;&lt;b&gt;Step 4: Make a GraphQL query to query data from the user table and the Auth0 profile information simultaneously&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcpm3abrylj4b077c680e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcpm3abrylj4b077c680e.png"&gt;&lt;/a&gt;&lt;/p&gt;
Make a GraphQL query to query data from the user table and the Auth0 profile information simultaneously







&lt;h2&gt;Use-case #3: Joining data across 2 separate databases&lt;h2&gt;

&lt;/h2&gt;
&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Falkei41fqwuiktgyuws7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Falkei41fqwuiktgyuws7.png"&gt;&lt;/a&gt;&lt;/p&gt;
Joining data across 2 databases



&lt;p&gt;The title says it all 🤓. And here's how this works with Hasura!&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Step 1: Setup Hasura to point to Database 1 and Database 2 with the right access control rules so that your GraphQL API is secure.&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fz8bc7hnxue0z8k03rmj7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fz8bc7hnxue0z8k03rmj7.png"&gt;&lt;/a&gt;&lt;/p&gt;
The "remote" Hasura + Postgres



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvq09byicsi5ut7mfqeke.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvq09byicsi5ut7mfqeke.png"&gt;&lt;/a&gt;&lt;/p&gt;
The "primary" Hasura + Postgres



&lt;p&gt;&lt;b&gt;Step 2: On the Hasura of your "primary" database, add the second Hasura as a remote schema&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcagseommrdjhw6697k7q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcagseommrdjhw6697k7q.png"&gt;&lt;/a&gt;&lt;/p&gt;
On the Hasura of your "primary" database, add the second Hasura as a remote schema



&lt;p&gt;&lt;b&gt;Step 3: Set up remote relationships from any table in your "primary" database to  resolvers in the other database.&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fukqmeq9956kbz4rd6tsv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fukqmeq9956kbz4rd6tsv.png"&gt;&lt;/a&gt;&lt;/p&gt;
Set up remote relationships from any table in your "primary" database to resolvers in the other database



&lt;p&gt;&lt;b&gt;Step 4: Run a GraphQL query that joins data across 2 databases!&lt;/b&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnk7544owsgm4qpyzsbfc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnk7544owsgm4qpyzsbfc.png"&gt;&lt;/a&gt;&lt;/p&gt;
A GraphQL query that joins data across 2 databases!






&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; 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.&lt;/p&gt;

&lt;p&gt;Try it out and let us know what you think! We ❤️ your feedback. Hit us up on our &lt;a href="https://github.com/hasura/graphql-engine" rel="noopener noreferrer"&gt;github&lt;/a&gt; or on &lt;a href="https://discordapp.com/invite/hasura" rel="noopener noreferrer"&gt;discord&lt;/a&gt;. Remote Joins will be out of preview and released very very soon for production use!&lt;/p&gt;




&lt;p&gt;This article was originally written and published by &lt;a href="https://twitter.com/tanmaigo" rel="noopener noreferrer"&gt;Tanmai Gopal&lt;/a&gt; on the &lt;a href="https://blog.hasura.io/remote-joins-a-graphql-api-to-join-database-and-other-data-sources/" rel="noopener noreferrer"&gt;Hasura blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>hasura</category>
      <category>postgres</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
