Skip to main content
Version: v3.x

Relationships

In this section, we implement relationships to link database tables, transforming our database into a subgraph within Hasura's supergraph.

We start by adding a foreignKeys property to the TableConfiguration type and updating our configuration.json. Then, we modify the get_schema function to include these relationships.

Next, we refactor the fetch_rows function to generate SQL without executing it, enabling the explain endpoint. We update the capabilities endpoint and handle relationship fields by generating SQL subqueries with unique table names to avoid collisions.

The fetch_relationship function generates SQL for relationship fields, aggregating related rows into JSON arrays using SQLite functions. We also implement postprocessing to correctly format the returned JSON data.

Lastly, we enable exists expressions to support complex query scenarios. This tutorial equips our connector with basic relationship query support, setting the stage for advanced features.

Let's get started...

Loading...