hasura / hasura/graphql-engine

rfc: multi-column foreign key relationships

Open
#6,842 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

Currently relationships based on foreign key constraints would only work for single column constraints. Console works around this issue by creating `manual_configuration` in such cases. Ideally this isn't much work to support on the server and opens up possibilities for improved query generation (see https://github.com/hasura/graphql-engine/issues/5949).

## Object relationships:

- Many-To-One:

```
name: RelationshipName
table: TableName
using:
foreign_key_constraint_on: ColumnName | [ColumnName]
manual_configuration:
```

- One-To-One:
```
name: RelationshipName
table: TableName
using:
foreign_key_constraint_on:
table: TableName
# column will now be deprecated
column: ColumnName
# only one of column/columns should be present
columns: ColumnName | [ColumnName]
manual_configuration:
```

## Array Relationships:

```
name: RelationshipName
table: TableName
using:
foreign_key_constraint_on:
table: TableName
# column will now be deprecated
column: ColumnName
# only one of column/columns should be present
columns: ColumnName | [ColumnName]
manual_configuration:
```

## Potential issues

`export_metadata` will now have single element column arrays:

- Previously

```
table: article
name: author
using:
foreign_key_constraint_on: author_id
```

- After this change

```
table: article
name: author
using:
foreign_key_constraint_on: [author_id]
```

Contributor guide

Open the contributing guide

Research direction

The issue names no files, tests, or entry points; start by tracing server handling of foreign_key_constraint_on metadata and existing manual_configuration relationships. Done means multi-column object and array relationships are supported, and exported metadata uses the specified column-array representation.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, postgres
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.