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

Bugfix relationship 1:1 nullability #559

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,13 +1952,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 @@ -2127,6 +2133,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 @@ -2180,7 +2187,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 @@ -2202,6 +2213,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
Loading