graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Postgres many-to-many table relationships should be non-null

Open arjunyel opened this issue 1 year ago • 6 comments

Component

c/v3-ndc-postgres

What is the current behaviour?

The objects linked to a many-to-many table are nullable

What is the expected behaviour?

The linked models should be non-null.

How to reproduce the issue?

  1. Make many-to-many table and link to other models
  2. Check GraphQL type

Screenshots or Screencast

Should be User! and Tag!

image

Please provide any traces or logs that could help here.

Any possible solutions/workarounds you're aware of?

Keywords

many-to-many table non-null

arjunyel avatar Jun 05 '24 06:06 arjunyel

Non null database columns on any table should show up as non null graphql types.

Does the join table have not null constraints applied to the join columns?

nullxone avatar Jun 06 '24 08:06 nullxone

Yes the columns are non null

arjunyel avatar Jun 06 '24 13:06 arjunyel

Thanks for the report. I'm relabeling this item because the cli is the component responsible for generating opendd spec for the engine from the ndc-spec schema response that ndc-postgres returns. In that schema response ndc-postgres only reports foreign keys, and is not responsible for the nullability of a relationship model in graphql types.

soupi avatar Jun 06 '24 14:06 soupi

I understand the issue now, the relationships themselves should be non nullable, not the fields. We will get back to you. (editing this message to reflect my updated understanding)

nullxone avatar Jun 07 '24 07:06 nullxone

@arjunyel had a word with the team

For a general relationship, although the key may be present on the source table, it is not guaranteed that the corresponding row is present on the target table. That is why, for a general relationship, the graphql relationship is nullable.

However, if the database makes additional guarantees (like non nullable foreign keys constraints), we could potentially make the relationship non nullable as well. This is a feature we can look into adding to the engine metadata.

nullxone avatar Jun 10 '24 09:06 nullxone

@nullxone this makes working with relationships in client code really difficult, I am having to override auto generated typescript types manually

arjunyel avatar Jun 17 '24 15:06 arjunyel