Skip to content

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

Open
@jgzuke

Description

@jgzuke

I'm submitting a ...

  • bug report
  • feature request
  • question

PostGraphile version: v4.4.0

Given the following 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.

{
  # 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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    🐭 Shrew

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions