graphile / graphile/graphile-engine

Feature Request: Expose 1 to 1 relation by rest of Composite key on object

Open
#670 2 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
764
Forks
128
PR merge metrics
No merged PRs in 30d

Description

I'm submitting a ...

* [ ] bug report
* [x] feature request
* [ ] question

PostGraphile version: v4.4.0

Given the following SQL
```sql
CREATE TABLE languages("id" SMALLINT PRIMARY KEY);
CREATE TABLE foo("id" SMALLINT PRIMARY KEY);
CREATE TABLE foo_names
(
"foo_id" SMALLINT NOT NULL REFERENCES foo(id),
"language_id" SMALLINT NOT NULL REFERENCES languages(id),
"name" VARCHAR (16) NOT NULL UNIQUE,
PRIMARY KEY(foo_id, language_id)
);
```
I would like to be able to request resources with a composite key referencing the current object by just the other fields in the composite key.
```gql
{
# Without `pg-simplify-inflector` renames to show more clearly
allFoos {
nodes {
# Current solution
fooNamesByFooId(condition: { languageId: 1 }) {
# Will always return a list with asingle element since
# (languageId, fooId) is the key for fooNames
nodes {
name
}
}
# What I want to do here:
fooNamesByFooIdAndLanguageId(languageId: 1) {
# Returning the element directly
name
}
}
}
}
```

I could not find any way to accomplish this currently. Is this something that you would be interested in a PR/plugin for?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.