add better upsert example to docs (#1930)

This commit is contained in:
Rikin Kachhia 2019-04-03 15:05:51 +05:30 committed by GitHub
parent f147f6d6a6
commit 29d6e85e42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,44 +33,53 @@ upsert request in case of conflicts.
Update selected columns on conflict
-----------------------------------
Insert a new object in the author table or, if the primary key constraint, ``author_pkey``, is violated, update the columns
specified in ``update_columns``:
Insert a new object in the ``article`` table or, if the primary key constraint, ``article_pkey``, is violated, update
the columns specified in ``update_columns``:
.. graphiql::
:view_only:
:query:
mutation upsert_author {
insert_author(
mutation upsert_article {
insert_article (
objects: [
{name: "John", id: 10}
{
id: 2,
title: "ex quis mattis",
content: "Pellentesque lobortis quam non leo faucibus efficitur",
published_on: "2018-10-12"
}
],
on_conflict: {
constraint: author_pkey,
update_columns: [name]
constraint: article_pkey,
update_columns: [title, content]
}
) {
affected_rows
returning{
returning {
id
name
title
content
published_on
}
}
}
:response:
{
"data": {
"insert_author": {
"affected_rows": 1,
"insert_article": {
"returning": [
{
"name": "John",
"id": 10
}
]
{
"id": 2,
"title": "ex quis mattis",
"content": "Pellentesque lobortis quam non leo faucibus efficitur",
"published_on": "2018-06-10"
}
]
}
}
}
The ``published_on`` column is left unchanged as it wasn't present in ``update_columns``.
Ignore request on conflict
--------------------------
If ``update_columns`` is an **empty array** then GraphQL Engine ignore changes on conflict. Insert a new object into
@ -101,7 +110,7 @@ the author table or, if the unique constraint, ``author_name_key``, is violated,
}
}
In this case, the insert mutation is ignored because there is a conflict.
In this case, the insert mutation is ignored because there is a conflict and ``update_columns`` is empty.
Upsert in nested mutations