mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-20 22:11:45 +03:00
fe8eabff19
When adding object relationships, we set the nullability of the generated GraphQL field based on whether the database backend enforces that the referenced data always exists. For manual relationships (corresponding to `manual_configuration`), the database backend is unaware of any relationship between data, and hence such fields are always set to be nullable. For relationships generated from foreign key constraints (corresponding to `foreign_key_constraint_on`), we distinguish between two cases: 1. The "forward" object relationship from a referencing table (i.e. which has the foreign key constraint) to a referenced table. This should be set to be non-nullable when all referencing columns are non-nullable. But in fact, it used to set it to be non-nullable if *any* referencing column is non-nullable, which is only correct in Postgres when `MATCH FULL` is set (a flag we don't consider). This fixes that by changing a boolean conjunction to a disjunction. 2. The "reverse" object relationship from a referenced table to a referencing table which has the foreign key constraint. This should always be set to be nullable. But in fact, it used to always be set to non-nullable, as was reported in hasura/graphql-engine#7201. This fixes that. Moreover, we have moved the computation of the nullability from `Hasura.RQL.DDL.Relationship` to `Hasura.GraphQL.Schema.Select`: this nullability used to be passed through the `riIsNullable` field of `RelInfo`, but for array relationships this information is not actually used, and moreover the remaining fields of `RelInfo` are already enough to deduce the nullability. This also adds regression tests for both (1) and (2) above. https://github.com/hasura/graphql-engine-mono/pull/2159 GitOrigin-RevId: 617f12765614f49746d18d3368f41dfae2f3e6ca
82 lines
1.7 KiB
YAML
82 lines
1.7 KiB
YAML
description: Test that object relationships have the correct nullability
|
|
url: /v1/graphql
|
|
status: 200
|
|
query:
|
|
query: |
|
|
query {
|
|
table1 : __type(name: "table1") {
|
|
fields {
|
|
name
|
|
type {
|
|
kind
|
|
}
|
|
}
|
|
}
|
|
table2 : __type(name: "table2") {
|
|
fields {
|
|
name
|
|
type {
|
|
kind
|
|
}
|
|
}
|
|
}
|
|
joint_foreign_key : __type(name: "joint_foreign_key") {
|
|
fields {
|
|
name
|
|
type {
|
|
kind
|
|
}
|
|
}
|
|
}
|
|
}
|
|
response:
|
|
data:
|
|
table1:
|
|
fields:
|
|
- name: id
|
|
type:
|
|
kind: NON_NULL
|
|
- name: name
|
|
type:
|
|
kind: SCALAR
|
|
- name: via_table2
|
|
type:
|
|
kind: OBJECT # this is what we're testing
|
|
- name: via_table2_not_null
|
|
type:
|
|
kind: OBJECT # this is what we're testing
|
|
table2:
|
|
fields:
|
|
- name: id
|
|
type:
|
|
kind: NON_NULL
|
|
- name: name
|
|
type:
|
|
kind: SCALAR
|
|
- name: table1_id
|
|
type:
|
|
kind: SCALAR
|
|
- name: table1_id_not_null
|
|
type:
|
|
kind: NON_NULL
|
|
- name: via_table1
|
|
type:
|
|
kind: OBJECT # this is what we're testing
|
|
- name: via_table1_not_null
|
|
type:
|
|
kind: NON_NULL # this is what we're testing
|
|
joint_foreign_key:
|
|
fields:
|
|
- name: id
|
|
type:
|
|
kind: NON_NULL
|
|
- name: table2
|
|
type:
|
|
kind: OBJECT # This is what we're testing
|
|
- name: table2_name
|
|
type:
|
|
kind: NON_NULL
|
|
- name: table2_table1_id
|
|
type:
|
|
kind: SCALAR
|