Remote Schema to Remote Schema relationships
Remote schema to remote schema relationships (a.k.a GraphQL joins) extend the concept of joining data across tables, to joining across remote GraphQL sources. Once you create relationships between types from the GraphQL 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.
Relationships from remote schema to remote schema are supported from versions
v2.6.0 and above.
Create remote schema relationships
Step 0: Add two remote schemas
Add two remote schemas as described here, if the schemas aren't 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 Schemas: Select two remote schemas 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 first remote schema
order-remote-schema has a field
order(id int, user_id int)
and our second remote schema
user-remote-schema - which is another GraphQL API - has a field
user(id int, name text). Now we want to create a relationship between the
order field of the first remote schema and
user field of the second remote schema.
- We name the relationship
- We select the source type
Orderof the remote schema that we'd like to join.
- We select
user-remote-schemaas the reference remote schema.
- We select
idas the source field and
user_idas the from field.
Head to the
Remote schema -> [remote-schema-name] -> Relationshipstab.
Add a new relationshipbutton.
Define the relationship and hit
remote_schemas.yaml file in the
- name: order-remote-schema
Apply the metadata by running:
hasura metadata apply
POST /v1/metadata HTTP/1.1
Step 2: Explore with GraphiQL
API tab, test out your remote schema relationship.