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

deleteBy<key> does not seem to delete related records #22

Open
archlemon opened this issue Aug 15, 2019 · 1 comment · Fixed by #25
Open

deleteBy<key> does not seem to delete related records #22

archlemon opened this issue Aug 15, 2019 · 1 comment · Fixed by #25

Comments

@archlemon
Copy link
Contributor

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.

@archlemon archlemon changed the title deleteBy<key> does not seem to be working correctly deleteBy<key> does not seem to delete related records Aug 15, 2019
archlemon added a commit to archlemon/postgraphile-plugin-nested-mutations that referenced this issue Oct 21, 2019
juliendangers pushed a commit to sterblue/postgraphile-plugin-nested-mutations that referenced this issue Sep 1, 2020
@mlipscombe
Copy link
Owner

I'm reopening this after reverting the merge, because it breaks other stuff. I'll investigate.

@mlipscombe mlipscombe reopened this Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants