Skip to content

Commit

Permalink
Merge pull request #559 from supabase/or/1-1-nullability
Browse files Browse the repository at this point in the history
Bugfix relationship 1:1 nullability
  • Loading branch information
olirice authored Sep 27, 2024
2 parents 9cfce02 + 896c22c commit 8e0ca67
Show file tree
Hide file tree
Showing 5 changed files with 481 additions and 66 deletions.
16 changes: 14 additions & 2 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1946,13 +1946,19 @@ pub fn sql_column_to_graphql_type(col: &Column, schema: &Arc<__Schema>) -> Optio
}

impl NodeType {
fn foreign_key_type(&self, fkey: &ForeignKey, type_: __Type) -> __Type {
fn foreign_key_type(
&self,
fkey: &ForeignKey,
type_: __Type,
is_reverse_reference: bool,
) -> __Type {
if fkey.local_table_meta.column_names.iter().any(|colname| {
self.table
.columns
.iter()
.any(|c| &c.name == colname && c.is_not_null)
&& !fkey.referenced_table_meta.is_rls_enabled
&& !is_reverse_reference
}) {
__Type::NonNull(NonNullType {
type_: Box::new(type_),
Expand Down Expand Up @@ -2121,6 +2127,7 @@ impl ___Type for NodeType {
reverse_reference: Some(reverse_reference),
schema: Arc::clone(&self.schema),
}),
reverse_reference,
);

let relation_field = __Field {
Expand Down Expand Up @@ -2174,7 +2181,11 @@ impl ___Type for NodeType {
};
let connection_args = connection_type.get_connection_input_args();

let type_ = self.foreign_key_type(fkey, __Type::Connection(connection_type));
let type_ = self.foreign_key_type(
fkey,
__Type::Connection(connection_type),
reverse_reference,
);

__Field {
name_: self
Expand All @@ -2196,6 +2207,7 @@ impl ___Type for NodeType {
reverse_reference: Some(reverse_reference),
schema: Arc::clone(&self.schema),
}),
reverse_reference,
);

__Field {
Expand Down
126 changes: 63 additions & 63 deletions test/expected/issue_542_partial_unique.out
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,42 @@ begin;
}
$$)
);
jsonb_pretty
-------------------------------------------------------
{ +
"data": { +
"__type": { +
"kind": "OBJECT", +
"fields": [ +
{ +
"name": "nodeId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "workId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "readthroughsCollection",+
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
} +
] +
} +
} +
jsonb_pretty
----------------------------------------------------------
{ +
"data": { +
"__type": { +
"kind": "OBJECT", +
"fields": [ +
{ +
"name": "nodeId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "workId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "readthroughsCollection", +
"type": { +
"kind": "OBJECT", +
"name": "ReadthroughsConnection"+
} +
} +
] +
} +
} +
}
(1 row)

/* Creating partial unique referencing status should NOT change the relationship with
the readthroughs to a non-null unique because its partial and other statuses may
the readthroughs to a 1:1 because its partial and other statuses may
have multiple associated readthroughs */
create unique index idx_unique_in_progress_readthrough
on public.readthroughs (work_id)
Expand All @@ -79,37 +79,37 @@ begin;
}
$$)
);
jsonb_pretty
-------------------------------------------------------
{ +
"data": { +
"__type": { +
"kind": "OBJECT", +
"fields": [ +
{ +
"name": "nodeId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "workId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "readthroughsCollection",+
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
} +
] +
} +
} +
jsonb_pretty
----------------------------------------------------------
{ +
"data": { +
"__type": { +
"kind": "OBJECT", +
"fields": [ +
{ +
"name": "nodeId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "workId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "readthroughsCollection", +
"type": { +
"kind": "OBJECT", +
"name": "ReadthroughsConnection"+
} +
} +
] +
} +
} +
}
(1 row)

Expand Down
Loading

0 comments on commit 8e0ca67

Please sign in to comment.