BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Hasura Remote Joins Implements GraphQL Data Federation

Hasura Remote Joins Implements GraphQL Data Federation

This item in japanese

Hasura Remote Joins allows developers to use a single data graph to query several underlying data sources. Doing so does not force developers to modify the federated data sources. Developers instead configure the relationships between the federated data models. The unified GraphQL API, combined with Hasura’s handling of authorization and caching, may provide more consistent and secure data access at scale.

Data sources may expose different interfaces like GraphQL, REST, or SQL servers. The Hasura website illustrates how federation works. In the illustration, a unified GraphQL query contains data items from several remote sources (a profile id and name come from a Postgres database while addresses comes from a REST resource):

GraphQL query with data from several sources

Hasura then queries both data sources in parallel, and federates the data received by both sources:

Federation of data received by both sources

Remote Joins generalizes the concept of locally joining SQL tables, to being able to join data across any part of a GraphQL schema. Unlike schema stitching, which requires the developer to write careful imperative code, Remote Joins follows a declarative approach. Developers configure external data sources as remote schemas. Developers then provide the join configuration from table columns to remote schema fields by means of a dedicated UI:

remote-rel-configuration
(Source: Hasura 1.3 release note)

One Hasura blog explained how remote joins can be leveraged in real-world applications:

Imagine building an e-commerce website with a user’s order page getting data from Postgres as well as Stripe in a single query. Or having multiple domain databases and performing a join across them similar to a normalized table join.

Besides data federation, remote joins also provide performance, security, and consistency benefits. Hasura creates an efficient execution plan which pushes down most of the heavy-lifting involved to underlying sources. Hasura may batch calls to remote schemas to avoid the n+1 problem . Security-wise, Hasura’s role-based access control extends to remote schemas. Hasura will forward session variables that can be used to implement custom authorization.

Documentation for Remote Joins is available online. Tirumarai Selvan showcased Remote Joins in a talk at Hasura Con 2020 (Using Remote Joins to Create a Unified GraphQL API for Your Company).

The Hasura GraphQL Engine was open-sourced in 2018 and has been enabling developers to set up GraphQL endpoints on their existing Postgres applications. Hasura emphasizes developer productivity and performance. It strives to allow developers to declaratively configure a web-server in minutes and expose a production-ready API by referencing an existing Postgres database.

The Hasura engine additionally has event triggers that allow custom microservices and serverless functions to provide additional processing behavior. Hasura compiles a GraphQL query of any depth to a single SQL query.

Rate this Article

Adoption
Style

BT