hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.18k stars 2.77k forks source link

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

Open arjunyel opened 5 months ago

arjunyel commented 5 months ago

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

nullxone commented 5 months ago

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?

arjunyel commented 5 months ago

Yes the columns are non null

soupi commented 5 months ago

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.

nullxone commented 5 months ago

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 commented 5 months ago

@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.

arjunyel commented 4 months ago

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