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

Optionality of a compound-key relationship wrong #8683

Open
juanluispaz opened this issue Jul 11, 2022 · 0 comments
Open

Optionality of a compound-key relationship wrong #8683

juanluispaz opened this issue Jul 11, 2022 · 0 comments
Labels
k/bug Something isn't working

Comments

@juanluispaz
Copy link

Version Information

Server Version: 2.8.4
CLI Version (for CLI related issue):

Environment

OSS Docker version following https://hasura.io/docs/latest/graphql/core/getting-started/docker-simple/

What is the current behaviour?

For the following database

CREATE TABLE project (
    id SERIAL NOT NULL,
    name VARCHAR(300) NOT NULL, 
    PRIMARY KEY (id)
);

CREATE TABLE subcontract (
    id SERIAL NOT NULL,
    name VARCHAR(300) NOT NULL, 
    project_id INTEGER NOT NULL,
    PRIMARY KEY (project_id, id),
    FOREIGN KEY (project_id) REFERENCES project (id)
);

CREATE TABLE invoice (
    id SERIAL NOT NULL,
    title VARCHAR(300) NOT NULL,
    subcontract_id INTEGER NOT NULL,
    project_id INTEGER NOT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (project_id, subcontract_id) REFERENCES subcontract (project_id, id),
    FOREIGN KEY (project_id) REFERENCES project (id)
);

The following definition is generated for the invoice table

"""
columns and relationships of "invoice"
"""
type invoice {
  id: Int!

  """An object relationship"""
  project: project!
  project_id: Int!

  """An object relationship"""
  subcontract: subcontract # this field is not marked as required
  subcontract_id: Int!
  title: String!
}

Where the subcontract relation is marked as optional where it should be required

What is the expected behaviour?

The following definition is generated for the invoice table

"""
columns and relationships of "invoice"
"""
type invoice {
  id: Int!

  """An object relationship"""
  project: project!
  project_id: Int!

  """An object relationship"""
  subcontract: subcontract! # this field should be marked as required
  subcontract_id: Int!
  title: String!
}

Where the subcontract relation is marked should be marked as required because all keys part of the foreign key are required

How to reproduce the issue?

  1. Create the tables in with the provided sql
  2. Track all tables
  3. Track all relationships

Screenshots or Screencast

Not apply

Please provide any traces or logs that could help here.

No error thrown

Any possible solutions?

Expected behaviour: If all fields of a foreign key are required the field should be marked as required, otherwise it must be optional.
Current behaviour: always it is optional no matter what.

Can you identify the location in the source code where the problem exists?

No idea

If the bug is confirmed, would you be willing to submit a PR?

No idea where to start

Keywords

@juanluispaz juanluispaz added the k/bug Something isn't working label Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
k/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant