From 46ac68952fb6bfd11ed1f9d38e509d82e2524579 Mon Sep 17 00:00:00 2001 From: Marion Schleifer Date: Tue, 10 Dec 2019 11:37:20 +0100 Subject: [PATCH] add replace nested objects example to update docs (#2962) --- docs/graphql/manual/mutations/update.rst | 52 +++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/docs/graphql/manual/mutations/update.rst b/docs/graphql/manual/mutations/update.rst index 79493341de3..cf5b250079e 100644 --- a/docs/graphql/manual/mutations/update.rst +++ b/docs/graphql/manual/mutations/update.rst @@ -230,7 +230,6 @@ evaluates to ``true`` for all objects. } } - Increment **int** columns ------------------------- You can increment an ``int`` column with a given value using the ``_inc`` operator. @@ -497,3 +496,54 @@ The input value should be a ``String Array``. } } +Replace all nested array objects of an object +--------------------------------------------- + +In order to replace all existing nested array objects of an object, currently it's required to use two mutations: +one to delete all the existing objects and one to add a list of new nested objects. + +**Example:** Replace all articles of an author with a new list: + +.. graphiql:: + :view_only: + :query: + mutation updateAuthorArticles($author_id: Int!) { + delete_articles( + where: {author_id: {_eq: $author_id}} + ) { + affected_rows + } + insert_articles( + objects: [ + { + author_id: $author_id, + title: "title", + content: "some content" + }, + { + author_id: $author_id, + title: "another title", + content: "some other content" + } + ] + ) { + affected_rows + } + } + :response: + { + "data": { + "delete_article_tags": { + "affected_rows": 3 + }, + "insert_article_tags": { + "affected_rows": 2 + } + } + } + :variables: + { + "author_id": 21 + } + +