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

nestedMutationsSimpleFieldNames inflection conflict with multiple FKEY relations to same table #18

Open
frankdugan3 opened this issue Mar 30, 2019 · 1 comment

Comments

@frankdugan3
Copy link

Given the table:

CREATE TABLE hsm_public.gage_calibration_record (
  id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(),
  -- ...
  gage_id uuid NOT NULL REFERENCES hsm_public.gage(id) ON DELETE RESTRICT,
  standard_id uuid REFERENCES hsm_public.gage(id) ON DELETE RESTRICT
);

The following input type is generated:

input CreateGageCalibrationRecordInput {
  id: UUID
  # ...
  gageId: UUID
  standardId: UUID
  gageToGageId: GageCalibrationRecordGageIdFkeyInput
  gageToStandardId: GageCalibrationRecordStandardIdFkeyInput
}

So far, so good. But when I use the nestedMutationsSimpleFieldNames: true option, it simplifies to this:

input CreateGageCalibrationRecordInput {
  id: UUID
  # ...
  gageId: UUID
  standardId: UUID
  gage: GageCalibrationRecordStandardIdFkeyInput
}

This convention steamrolls the second relation to the gage table, and it removes the clarity provided by the column's original name. Perhaps it could use the column name for inflection rather than the foreign table? At the very least, if more than one FKEY points to the same table, it should skip simplification. Since [relation]_id is a pretty common convention, FKEY columns that match that format could simply strip _id from the column name, producing for my example:

input CreateGageCalibrationRecordInput {
  id: UUID
  # ...
  gageId: UUID
  standardId: UUID
  gage: GageCalibrationRecordGageIdFkeyInput
  standard: GageCalibrationRecordStandardIdFkeyInput
}
@mlipscombe
Copy link
Owner

This can be worked around at least by using @forwardMutationName and @reverseMutationName to set the nested names as you wish.

Special casing [relation]_id would be a schema-breaking change for existing users, so it would have to be gated behind a configuration option, or part of a major version bump.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants