graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Issue with nested inserts

Open rikinsk-zz opened this issue 6 years ago • 1 comments

For object relationships we shouldn't be allowed to insert a nested object if its reference column is not a part of update_columns

Currently the nested object gets created but the reference column is not updated in the parent.

For example:

If I have an article with id=1 and author_id=1, the below request will create new author with id=2 but the article will remain unchanged i.e. will still have author_id=1

Request:

mutation {
  insert_test_schema_article(
    objects: [
      {
        id: 1,
        title: "Article 1"
        author: {
          data: {
            id: 2,
            name: "Rikin"
          }
        }
      }
    ],
    on_conflict: {
      constraint: article_pkey,
      update_columns: []
    }
  ) {
    affected_rows
    returning {
      id
      title
      author {
        id
        name
      }
    }
  }
}

Response:

{
  "data": {
    "insert_test_schema_article": {
      "affected_rows": 2,
      "returning": [
        null
      ]
    }
  }
}

Author should be be inserted only if Article get updated

rikinsk-zz avatar Jan 30 '19 15:01 rikinsk-zz

~~I have the exact same issue.~~ ~~The expected behavior is if the parent violates the on_conflict condition, the nested object mutation shouldn't be executed.~~

Could we raise the priority of this issue?

tz-torchai avatar Sep 15 '22 05:09 tz-torchai