Postgres: Remote relationships
Remote relationships (aka "remote joins") allow you to join data across tables and remote data sources. The remote data source can either be a remote schema, a table from a second database source, or the type returned from an action. Once you create relationships between types from your database tables and types created from remote schemas or actions, you can then "join" them by running GraphQL queries.
See the following guides on how to create different types of remote relationships related to Postgres:
- Database to database relationships: To join data across tables between two different database sources, such as order information stored in a Postgres database, and user information stored in a separate Postgres or say a SQL Server database.
- Database to Remote Schema relationships: To join data across tables and remote GraphQL APIs. For example, you can join customer data from your tables with account data from Stripe, Spotify, or Auth0.
- Remote Schema to database relationships: To join data from your remote schemas (such as Stripe, Spotify or Auth0) to customer data from your tables.
- Action to database relationships: To join data
across tables and actions (i.e. Rest APIs). For example, you can join
userdata from your database with the response from a
createUseraction, using the
Hasura's remote joins architecture provides the following benefits.
- Security: Hasura's authorization model gives you role-based access control. This
extends to actions and remote schemas as well. In actions, you can go to the
Permissionstab and choose which fields to expose for which roles. For remote schemas, Hasura will forward your session variables which can be used to implement custom authorization in your remote schemas. Native role-based permissions on remote schemas is in the works.
- Performance: Hasura strives for optimal performance. It creates an efficient execution plan which pushes down most of the heavy-lifting involved to underlying sources. For example, Hasura creates a single efficient query to your database and batches calls to remote schemas to avoid the n+1 problem . More improvements to performance are upcoming.
- Schema integrity & consistency: Hasura has metadata consistency checks at every level. Whenever you add a table, remote schema, or action, Hasura makes sure that the graph that is exposed is consistent, and that all the relationships make sense at a type level. This helps you in creating robust workflows to test changes in your CI and making safe deployments of your unified graph.
- Data federation: With remote joins, the join, authorization, and consistency checks of added sources all happen at the Hasura layer via metadata. This allows underlying data sources and APIs to evolve independently. Your applications have a unified API to query the full data landscape in your org.