postgraphile-plugin-nested-mutations
postgraphile-plugin-nested-mutations copied to clipboard
deleteBy<key> does not seem to delete related records
I'm not sure if I'm not using it correctly, but I cannot get it to work as I'm expecting.
I have two tables:
create table app.asset (
id uuid primary key default public.uuid_generate_v4(),
);
create table app.person (
id uuid primary key default public.uuid_generate_v4(),
avatar_id uuid references app.asset_id on delete set null
);
Running the following mutation, I'd expect the asset to be deleted. (I'm also trying to set avatarId to null, for debugging the queries.):
mutation {
updatePersonById(input:{
id:"49b78602-b633-4f95-afc6-e279fa6de581"
personPatch:{
assetToAvatarId:{
deleteById:{
id:"1bb2f88c-3969-4400-9274-d1f467aea3bd"
}
}
avatarId:null
}
}) {
clientMutationId
}
}
This generates the following:
graph_1 | 2019-08-15T11:53:40.519Z postgraphile:postgres begin
graph_1 | 2019-08-15T11:53:40.520Z postgraphile:postgres SAVEPOINT graphql_nested_mutation
graph_1 | 2019-08-15T11:53:40.521Z postgraphile:postgres select "id"
graph_1 | from "app"."asset"
graph_1 | where "id" = $1
graph_1 | 2019-08-15T11:53:40.524Z postgraphile:postgres update "app"."person" set "avatar_id" = $1
graph_1 | where (
graph_1 | "id" = $2
graph_1 | ) returning *
graph_1 | 2019-08-15T11:53:40.526Z postgraphile:postgres with __local_0__ as (
graph_1 | select *
graph_1 | from "app"."person"
graph_1 | where "id" = $1
graph_1 | )
graph_1 | select (
graph_1 | (
graph_1 | case when __local_0__ is null then null else __local_0__ end
graph_1 | )
graph_1 | )::text
graph_1 | from __local_0__
graph_1 | 2019-08-15T11:53:40.527Z postgraphile:postgres with __local_0__ as (
graph_1 | select (
graph_1 | str::"app"."person"
graph_1 | ).*
graph_1 | from unnest(
graph_1 | (
graph_1 | $1
graph_1 | )::text[]
graph_1 | ) str
graph_1 | )
graph_1 | select to_json(__local_0__."id") as "__pk__id"
graph_1 | from __local_0__ as __local_0__
graph_1 | where (TRUE) and (TRUE)
graph_1 | 2019-08-15T11:53:40.529Z postgraphile:postgres RELEASE SAVEPOINT graphql_nested_mutation
graph_1 | 2019-08-15T11:53:40.530Z postgraphile:postgres commit
graph_1 | 0 error(s) in 20.86ms :: mutation { updatePersonById(input: {id: "49b78602-b633-4f95-afc6-e279fa6de581", personPatch: {assetToAvatarId: {deleteById: {id: "1bb2f88c-3969-4400-9274-d1f467aea3bd"}}, avatarId: null}}) { clientMutationId } }
Additionally, if I set the avatar_id to null, and then rerun the above query, it connects the two records and sets the avatar_id to the id in deleteById.
I'm reopening this after reverting the merge, because it breaks other stuff. I'll investigate.