Skip to main content
Version: v2.x

MS SQL Server: Database to Remote Schema relationships

Introduction

Database to Remote Schema 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 remote schemas, you can then "join" them by running GraphQL queries.

These APIs can be custom GraphQL servers you write, third party SaaS APIs, or even other Hasura instances.

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.

Note

To see example use cases, check out this blog post.

Supported from

Remote schema relationships from MS SQL Server 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 order(id int, user_id int) and we've added a remote schema user-remote-schema.

  1. We name the relationship user.
  2. We select the user-remote-schema that we've added.
  3. We set up the config to join the id input argument of our remote schema field to the user_id column of this table (in this case, the order table).
  • Head to the Data -> [table-name] -> Relationships tab.

  • Click the Add a remote relationship button.

    Opening the remote relationship section
  • Define the relationship and hit Save.

    Defining the relationship

Step 2: Explore with GraphiQL

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

GraphiQL
Query Variables
Request Headers

Remote schema relationship permissions

Remote schema relationship permissions are derived from the remote schema permissions defined for the role. When a remote relationship permission cannot be derived, the remote relationship field will not be added to the schema for the role.

Some cases in which a remote relationship permission cannot be derived are:

  1. There are no remote schema permissions defined for the role.
  2. The role doesn't have access to the field or types that are used by the remote relationship.
Note

Remote relationship permissions apply only if remote schema permissions are enabled in GraphQL engine.