mirror of
https://github.com/zhigang1992/graphql-engine.git
synced 2026-05-28 23:31:46 +08:00
From `alpha-40` we've been using a `WHERE` clause to fetch required rows and generate mutation response. This has a few limitations like the requirement of a primary key/unique constraint. This also returns inconsistent data on `delete` mutation as mentioned in #1794. Now, we're using `VALUES (..)` (refer [here](https://www.postgresql.org/docs/current/sql-values.html)) expression to form virtual table rows in `SQL` to generate mutation response. Internal changes:- - Not to use primary key/unique constraint columns:- - Revert back to `ConstraintName` from `TableConstraint` in `TableInfo` type - Remove `tcCols` field in `TableConstraint` type - Modify `table_info.sql` and `fetchTableMeta` function `SQL` - A test case to perform `delete` mutation and returning relational objects.
This commit is contained in:
committed by
Shahidh K Muhammed
parent
420dde77dc
commit
5bafdce9a3
@@ -238,34 +238,11 @@ Mutation Response
|
||||
^^^^^^^^^^^^^^^^^
|
||||
.. code-block:: none
|
||||
|
||||
# if table has atleast one primary key or
|
||||
# one unique constraint with not null columns
|
||||
{
|
||||
affected_rows
|
||||
returning {
|
||||
col-field1
|
||||
col-field2
|
||||
..
|
||||
relation1{
|
||||
relation1-field1
|
||||
relation1-field2
|
||||
..
|
||||
}
|
||||
relation2{
|
||||
relation2-field1
|
||||
relation2-field2
|
||||
..
|
||||
}
|
||||
..
|
||||
}
|
||||
}
|
||||
|
||||
# if table has no primary key or unique constraints
|
||||
{
|
||||
affected_rows
|
||||
returning {
|
||||
col-field1
|
||||
col-field2
|
||||
response-field1
|
||||
response-field2
|
||||
..
|
||||
}
|
||||
}
|
||||
@@ -274,22 +251,6 @@ E.g.:
|
||||
|
||||
.. code-block:: graphql
|
||||
|
||||
# if table has atleast one primary key or
|
||||
# one unique constraint with not null columns
|
||||
{
|
||||
affected_rows
|
||||
returning {
|
||||
id
|
||||
author_id
|
||||
articles{
|
||||
id
|
||||
title
|
||||
content
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# if table has no primary key or unique constraints
|
||||
{
|
||||
affected_rows
|
||||
returning {
|
||||
@@ -305,8 +266,6 @@ E.g.:
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
# if table has atleast one primary key or
|
||||
# one unique constraint with not null columns
|
||||
objects: [
|
||||
{
|
||||
field1: value,
|
||||
@@ -323,23 +282,12 @@ E.g.:
|
||||
},
|
||||
..
|
||||
]
|
||||
|
||||
# if table has no primary key or unique constraints
|
||||
objects: [
|
||||
{
|
||||
col_field1: value,
|
||||
col_field2: value
|
||||
..
|
||||
},
|
||||
..
|
||||
]
|
||||
# no nested objects
|
||||
|
||||
E.g.:
|
||||
|
||||
.. code-block:: graphql
|
||||
|
||||
# if table has atleast one primary key or
|
||||
# one unique constraint with not null columns
|
||||
objects: [
|
||||
{
|
||||
title: "Software is eating the world",
|
||||
@@ -353,14 +301,6 @@ E.g.:
|
||||
}
|
||||
]
|
||||
|
||||
# if table has no primary key or unique constraints
|
||||
objects: [
|
||||
{
|
||||
title: "Software is eating the world",
|
||||
content: "This week, Hewlett-Packard..."
|
||||
}
|
||||
]
|
||||
|
||||
.. _ConflictClause:
|
||||
|
||||
**on_conflict** argument
|
||||
|
||||
@@ -35,10 +35,8 @@ See the :ref:`delete mutation API reference <delete_syntax>` for the full specif
|
||||
|
||||
.. note::
|
||||
|
||||
- If a table is not in the ``public`` Postgres schema, the delete mutation field will be of the format
|
||||
``delete_<schema_name>_<table_name>``.
|
||||
- To fetch nested objects using relationships in the mutation response, the table needs to have either a primary
|
||||
key or a unique constraint with not null columns.
|
||||
If a table is not in the ``public`` Postgres schema, the delete mutation field will be of the format
|
||||
``delete_<schema_name>_<table_name>``.
|
||||
|
||||
Delete based on an object's fields
|
||||
----------------------------------
|
||||
|
||||
@@ -36,10 +36,8 @@ See the :ref:`insert mutation API reference <insert_upsert_syntax>` for the full
|
||||
|
||||
.. note::
|
||||
|
||||
- If a table is not in the ``public`` Postgres schema, the insert mutation field will be of the format
|
||||
``insert_<schema_name>_<table_name>``.
|
||||
- To fetch nested objects using relationships in the mutation response, the table needs to have either a primary
|
||||
key or a unique constraint with not null columns.
|
||||
If a table is not in the ``public`` Postgres schema, the insert mutation field will be of the format
|
||||
``insert_<schema_name>_<table_name>``.
|
||||
|
||||
Insert a single object
|
||||
----------------------
|
||||
@@ -217,10 +215,6 @@ Insert an object and get a nested object in response
|
||||
}
|
||||
}
|
||||
|
||||
.. note::
|
||||
|
||||
For this to work, the parent table (*in this case,* ``article``) needs to have either a primary key or a
|
||||
unique constraint.
|
||||
|
||||
Insert an object and its nested object in the same mutation
|
||||
-----------------------------------------------------------
|
||||
@@ -276,11 +270,6 @@ in the response
|
||||
}
|
||||
}
|
||||
|
||||
.. note::
|
||||
|
||||
For this to work, the parent table (*in this case,* ``article``) needs to have either a primary key or a
|
||||
unique constraint.
|
||||
|
||||
Insert an object with a JSONB column
|
||||
------------------------------------
|
||||
**Example:** Insert a new ``author`` object with a JSONB ``address`` column
|
||||
|
||||
@@ -39,10 +39,9 @@ See the :ref:`update mutation API reference <update_syntax>` for the full specif
|
||||
|
||||
- At least any one of ``_set``, ``_inc`` operators or the jsonb operators ``_append``, ``_prepend``, ``_delete_key``,
|
||||
``_delete_elem``, ``_delete_at_path`` is required.
|
||||
|
||||
- If a table is not in the ``public`` Postgres schema, the update mutation field will be of the format
|
||||
``update_<schema_name>_<table_name>``.
|
||||
- To fetch nested objects using relationships in the mutation response, the table needs to have either a primary
|
||||
key or a unique constraint with not null columns.
|
||||
|
||||
Update based on an object's fields
|
||||
----------------------------------
|
||||
|
||||
@@ -145,10 +145,6 @@ You can specify ``on_conflict`` clause while inserting nested objects
|
||||
}
|
||||
}
|
||||
|
||||
.. note::
|
||||
|
||||
For this to work, the parent table (*in this case,* ``author``) needs to have either a primary key or a
|
||||
unique constraint.
|
||||
|
||||
.. admonition:: Edge-cases
|
||||
|
||||
|
||||
Reference in New Issue
Block a user