Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 3 tasks
jgzuke opened this issue Jun 15, 2019 · 1 comment
Open
1 of 3 tasks

Comments

@jgzuke
Copy link

jgzuke commented Jun 15, 2019

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?

@benjie
Copy link
Member

benjie commented Jun 16, 2019

A PR for this would indeed be welcome. It would likely be to this file:

https://github.com/graphile/graphile-engine/blob/master/packages/graphile-build-pg/src/plugins/PgBackwardRelationPlugin.js#L140

In a similar way to how single relations were added.

Thanks!

@benjie benjie transferred this issue from graphile/crystal Sep 28, 2020
@benjie benjie added this to V5.0.0 Oct 5, 2023
@github-project-automation github-project-automation bot moved this to 🌳 Triage in V5.0.0 Oct 5, 2023
@benjie benjie moved this from 🌳 Triage to 🐭 Shrew in V5.0.0 Oct 5, 2023
@benjie benjie removed this from V5.0.0 May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants