Using Remote Joins to Create a Unified GraphQL API for Your Company

Rate this content
Bookmark

With Hasura Remote Joins, you can join your table data with a Stripe API or Github API or any GraphQL API. Without writing a single line of code. Using GraphQL's amazing type system combined with Hasura's declarative configuration, you can create relationships across tables and other services and get a beautiful unified API. In a single call, get all the data necessary for building your apps from anywhere in the world.

This talk has been presented at JSNation Live 2020, check out the latest edition of this JavaScript Conference.

FAQ

Hasura is an open-source GraphQL engine that connects to your Postgres database and other data sources like GraphQL and REST APIs, allowing them to be merged and joined together.

Hasura allows you to integrate and join multiple data sources, such as Postgres databases, other GraphQL APIs, and REST APIs, into a unified GraphQL API.

Remote joins in Hasura enable you to join data across different databases and APIs, such as fetching customer data from a Postgres database and Stripe data from the Stripe API, within a single GraphQL query.

Hasura provides features for authorization and other security measures to ensure that your GraphQL API is secure.

Hasura runs as a Docker container within your own infrastructure.

Yes, you can integrate Auth0 with Hasura by adding Auth0 as a remote schema and creating a relationship between your database table and the Auth0 GraphQL schema based on a common field like email.

You can join data from two different Hasura services by adding one service as a remote schema to the other and creating relationships between the tables using common fields like ID.

Hasura actions are a way to map REST endpoints to the GraphQL API, allowing you to integrate REST data sources with your GraphQL schema.

You can map a REST endpoint to a GraphQL API in Hasura by specifying the GraphQL specifications for the REST endpoint and creating an action that defines the data contract between them.

You can find Hasura on GitHub where you can give it a spin and contribute to its development.

Tanmai Gopal
Tanmai Gopal
9 min
18 Jun, 2021

Comments

Sign in or register to post your comment.
Video Summary and Transcription
The video explains how to use Hasura's remote joins feature to combine data from multiple sources into a unified GraphQL API. Hasura is an open-source GraphQL engine that connects to databases like Postgres and external sources such as a GraphQL API from Stripe or a REST API. Remote joins in Hasura allow you to merge data from these sources and query them together. For instance, you can integrate a Stripe GraphQL API to fetch payment details and combine it with user data from a Postgres database. The video also covers combining data from different databases, like a music database, and joining with a REST API using actions. These actions map REST endpoints to GraphQL specifications, enabling queries that return integrated data. The video demonstrates how to enrich the schema to query user details and fetch artist information, combining data from multiple endpoints. Check out remote joins and feel free to reach out on Twitter for questions.

1. Introduction to Remote Joins in Hasura

Short description:

I am Tanmay and I'm gonna talk to you a little bit about a new feature that we've been working on which is remote joins that allows you to kind of take multiple data sources and combine them into a unified GraphQL API. Hasura is an open source GraphQL engine that connects to your Postgres database but also other sources like a GraphQL source and a REST source and then allows you to kind of merge them together and now even join across them. Hasura runs as a Docker container in your own infrastructure.

Hi everyone. So glad to be here. I am Tanmay and I'm gonna talk to you a little bit about a new feature that we've been working on which is remote joins that allows you to kind of take multiple data sources and combine them into a unified GraphQL API. This is something that we've been doing at Hasura. Hasura is an open source GraphQL engine that connects to your Postgres database but also other sources like a GraphQL source and a REST source and then allows you to kind of merge them together and now even join across them. Hasura runs as a Docker container in your own infrastructure. Do check it out on Github, give it a spin. Let me know what you think.

2. Remote Joins and Integrating APIs

Short description:

You can combine data from a Postgres database and a GraphQL API, such as Stripe, using remote joins in Hasura. By integrating another GraphQL API, like Auth0, you can fetch additional details for each user. Adding the remote schema and creating a relationship allows you to query and fetch data from Auth0. Similarly, you can join across different databases, such as the music database in Hasura Remote Postgres.

So what I'm going to talk to you about is essentially being able to do something like this which is that you have data inside a Postgres database and you have a GraphQL API something like Stripe with OneGraph and what you want to do is make a GraphQL query that fetches the customer data from the database and maybe the Stripe data from the Stripe API as an example.

And so let's see what this looks like. Here I have Hasura running and this has just two tables which has user and events and what Hasura gives me is a GraphQL API on those tables. So what I can see is users and users have ID and e-mail and then I can make this GraphQL query. I can also do authorization and whatnot to make sure that this GraphQL API is actually secure.

And so what I'll be doing is now integrating another GraphQL API and then joining across that. So every user in my system has, for example, some is logged in with Auth0. And so they're going to have some Auth0 details like last login or profile details and stuff that are coming from the Auth0 service. And so I have a GraphQL API that's kind of wrapped over the Auth0 service. And so what I'll do is I'll take this and I'll add it as a remote schema in Hasura. So let's call it Auth0 and let's call it Auth0. And what I'll do is I'll add this as a URL here. And then what I can do is I can go to my user's table and I can create a relationship between my table and this GraphQL schema that I've added. So let's call it Auth0 profile and then let's say Auth0 and then choose to say that we want to use the email as a join condition, right? Because the email value is the same. Let's say I don't have the ID. I'm using email. I could have used ID as well, if the IDs were the same. As soon as I do that, what you'll see is that our GraphQL schema will get augmented and I'll be able to make a query to fetch details from Auth0. So that's a query where now I'm fetching this data from Auth0 as well. This data is coming in from Auth0. This data is coming in from our database.

Let's take another example where I can join across two databases. So I have another Hasura service and this is a different Hasura service. I've called it Hasura Remote Postgres, which has a music database. So there's like artists, albums, music tracks, stuff like that. It's kind of a standard demo app that I use. I'm going to take this GraphQL endpoint and add that to my main GraphQL schema here. Let's call it pgremote. And as soon as I add this here, let's go and add a relationship as well. So every user is also an artist.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
Tom Pressenwurter introduces Redwood.js, a full stack app framework for building GraphQL APIs easily and maintainably. He demonstrates a Redwood.js application with a React-based front end and a Node.js API. Redwood.js offers a simplified folder structure and schema for organizing the application. It provides easy data manipulation and CRUD operations through GraphQL functions. Redwood.js allows for easy implementation of new queries and directives, including authentication and limiting access to data. It is a stable and production-ready framework that integrates well with other front-end technologies.
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
This Talk discusses handling local state in software development, particularly when dealing with asynchronous behavior and API requests. It explores the challenges of managing global state and the need for actions when handling server data. The Talk also highlights the issue of fetching data not in Vuex and the challenges of keeping data up-to-date in Vuex. It mentions alternative tools like Apollo Client and React Query for handling local state. The Talk concludes with a discussion on GitLab going public and the celebration that followed.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
Envelope is a powerful GraphQL plugin system that simplifies server development and allows for powerful plugin integration. It provides conformity for large corporations with multiple GraphQL servers and can be used with various frameworks. Envelope acts as the Babel of GraphQL, allowing the use of non-spec features. The Guild offers GraphQL Hive, a service similar to Apollo Studio, and encourages collaboration with other frameworks and languages.
Rock Solid React and GraphQL Apps for People in a Hurry
GraphQL Galaxy 2022GraphQL Galaxy 2022
29 min
Rock Solid React and GraphQL Apps for People in a Hurry
The Talk discusses the challenges and advancements in using GraphQL and React together. It introduces RedwoodJS, a framework that simplifies frontend-backend integration and provides features like code generation, scaffolding, and authentication. The Talk demonstrates how to set up a Redwood project, generate layouts and models, and perform CRUD operations. Redwood automates many GraphQL parts and provides an easy way for developers to get started with GraphQL. It also highlights the benefits of Redwood and suggests checking out RedwoodJS.com for more information.
Adopting GraphQL in an Enterprise
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
Adopting GraphQL in an Enterprise
Today's Talk is about adopting GraphQL in an enterprise. It discusses the challenges of using REST APIs and the benefits of GraphQL. The Talk explores different approaches to adopting GraphQL, including coexistence with REST APIs. It emphasizes the power of GraphQL and provides tips for successful adoption. Overall, the Talk highlights the advantages of GraphQL in terms of efficiency, collaboration, and control over APIs.
Step aside resolvers: a new approach to GraphQL execution
GraphQL Galaxy 2022GraphQL Galaxy 2022
16 min
Step aside resolvers: a new approach to GraphQL execution
GraphQL has made a huge impact in the way we build client applications, websites, and mobile apps. Despite the dominance of resolvers, the GraphQL specification does not mandate their use. Introducing Graphast, a new project that compiles GraphQL operations into execution and output plans, providing advanced optimizations. In GraphFast, instead of resolvers, we have plan resolvers that deal with future data. Graphfast plan resolvers are short and efficient, supporting all features of modern GraphQL.

Workshops on related topic

Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Featured WorkshopFree
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
Build Modern Applications Using GraphQL and Javascript
Node Congress 2024Node Congress 2024
152 min
Build Modern Applications Using GraphQL and Javascript
Featured Workshop
Emanuel Scirlet
Miguel Henriques
2 authors
Come and learn how you can supercharge your modern and secure applications using GraphQL and Javascript. In this workshop we will build a GraphQL API and we will demonstrate the benefits of the query language for APIs and what use cases that are fit for it. Basic Javascript knowledge required.
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced 2022React Advanced 2022
95 min
End-To-End Type Safety with React, GraphQL & Prisma
Featured WorkshopFree
Sabin Adams
Sabin Adams
In this workshop, you will get a first-hand look at what end-to-end type safety is and why it is important. To accomplish this, you’ll be building a GraphQL API using modern, relevant tools which will be consumed by a React client.
Prerequisites: - Node.js installed on your machine (12.2.X / 14.X)- It is recommended (but not required) to use VS Code for the practical tasks- An IDE installed (VSCode recommended)- (Good to have)*A basic understanding of Node.js, React, and TypeScript
GraphQL for React Developers
GraphQL Galaxy 2022GraphQL Galaxy 2022
112 min
GraphQL for React Developers
Featured Workshop
Roy Derks
Roy Derks
There are many advantages to using GraphQL as a datasource for frontend development, compared to REST APIs. We developers in example need to write a lot of imperative code to retrieve data to display in our applications and handle state. With GraphQL you cannot only decrease the amount of code needed around data fetching and state-management you'll also get increased flexibility, better performance and most of all an improved developer experience. In this workshop you'll learn how GraphQL can improve your work as a frontend developer and how to handle GraphQL in your frontend React application.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Relational Database Modeling for GraphQL
GraphQL Galaxy 2020GraphQL Galaxy 2020
106 min
Relational Database Modeling for GraphQL
Top Content
WorkshopFree
Adron Hall
Adron Hall
In this workshop we'll dig deeper into data modeling. We'll start with a discussion about various database types and how they map to GraphQL. Once that groundwork is laid out, the focus will shift to specific types of databases and how to build data models that work best for GraphQL within various scenarios.
Table of contentsPart 1 - Hour 1      a. Relational Database Data Modeling      b. Comparing Relational and NoSQL Databases      c. GraphQL with the Database in mindPart 2 - Hour 2      a. Designing Relational Data Models      b. Relationship, Building MultijoinsTables      c. GraphQL & Relational Data Modeling Query Complexities
Prerequisites      a. Data modeling tool. The trainer will be using dbdiagram      b. Postgres, albeit no need to install this locally, as I'll be using a Postgres Dicker image, from Docker Hub for all examples      c. Hasura