Skip to main content
Version: v2.x

Remote Schema to database relationships

Introduction

Remote schema to database relationships extend the concept of joining data across tables, to joining across tables and remote GraphQL sources. Once you create relationships between types from your database and types created from the remote schema, you can then "join" them by running GraphQL queries.

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.

Supported from

Relationships from remote schema to database are supported from versions v2.6.0 and above.

Create remote schema relationships

Step 0: Add a remote schema and a database

Add a remote schema and a database as described here and here, if not already added.

Step 1: Define and create the relationship

The following fields can be defined for a remote schema relationship:

  • Name: Define a name for the relationship.
  • Remote Schema: Select a remote schema among all the ones you've created.
  • Configuration: Set up the join configuration, to inject values as input arguments of the remote schema field.
    • From column: Input injected from table column values.
    • From static value: Input injected from a static value of your choice.

For example, let's assume that our database has a table user(id integer, name text) and we've added a remote schema order-remote-schema which is another GraphQL API. Now we want to create a relationship between the order field of the remote schema and the user table of the source database.

  1. We name the relationship user.
  2. We select the source type Order of the remote schema that we'd like to join.
  3. We select pg1 as the reference database, public as the reference schema and user as the reference table.
  4. We select user_id as the source field and id as the reference column.
  • Head to the Remote schema -> [remote-schema-name] -> Relationships tab.

  • Click the Add a new relationship button.

    Opening the remote relationship section
  • Define the relationship and hit Add Relationship.

    Defining the relationship

Step 2: Explore with GraphiQL

In the GraphiQL tab, test out your remote schema relationship.

GraphiQL
Query Variables
Request Headers