mirror of
https://github.com/zhigang1992/graphql-engine.git
synced 2026-05-15 07:25:03 +08:00
add boolean expressions syntactic sugar notes in docs (#3510)
This commit is contained in:
@@ -300,6 +300,8 @@ BoolExp
|
||||
|
||||
AndExp_ | OrExp_ | NotExp_ | TrueExp_ | ColumnExp_
|
||||
|
||||
.. _AndExp:
|
||||
|
||||
AndExp
|
||||
######
|
||||
|
||||
@@ -309,6 +311,30 @@ AndExp
|
||||
_and: [BoolExp_]
|
||||
}
|
||||
|
||||
.. admonition:: Syntactic sugar
|
||||
|
||||
You can simplify an ``_and`` expression by passing the sub-expressions separated by a ``,``.
|
||||
|
||||
**For example:**
|
||||
|
||||
.. code-block:: graphql
|
||||
|
||||
{
|
||||
_and: [
|
||||
{ rating: { _gte: 4 } },
|
||||
{ published_on: { _gte: "2018-01-01" } }
|
||||
]
|
||||
}
|
||||
|
||||
# can be simplified to:
|
||||
|
||||
{
|
||||
rating: { _gte: 4 },
|
||||
published_on: { _gte: "2018-01-01" }
|
||||
}
|
||||
|
||||
.. _OrExp:
|
||||
|
||||
OrExp
|
||||
#####
|
||||
|
||||
@@ -318,6 +344,46 @@ OrExp
|
||||
_or: [BoolExp_]
|
||||
}
|
||||
|
||||
.. note::
|
||||
|
||||
The ``_or`` operator expects an array of expressions as input. Passing an object to it will result in the
|
||||
behaviour of the ``_and`` operator due to the way `GraphQL list input coercion <https://graphql.github.io/graphql-spec/June2018/#sec-Type-System.List>`_
|
||||
behaves.
|
||||
|
||||
**For example:**
|
||||
|
||||
.. code-block:: graphql
|
||||
|
||||
{
|
||||
_or: {
|
||||
rating: { _gte: 4 },
|
||||
published_on: { _gte: "2018-01-01" }
|
||||
}
|
||||
}
|
||||
|
||||
# will be coerced to:
|
||||
|
||||
{
|
||||
_or: [
|
||||
{
|
||||
rating: { _gte: 4 },
|
||||
published_on: { _gte: "2018-01-01" }
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# which is equivalent to:
|
||||
|
||||
{
|
||||
_or: [
|
||||
_and: [
|
||||
{ rating: { _gte: 4 } },
|
||||
{ published_on: { _gte: "2018-01-01" } }
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
NotExp
|
||||
######
|
||||
|
||||
|
||||
@@ -1024,6 +1024,10 @@ Fetch a list of articles published in a specific time-frame (for example: in yea
|
||||
}
|
||||
}
|
||||
|
||||
.. note::
|
||||
|
||||
It is possible to simplify the ``_and`` expression. See the :ref:`API reference <AndExp>` for more details.
|
||||
|
||||
**Example: _or**
|
||||
|
||||
Fetch a list of articles rated more than 4 or published after "01/01/2018":
|
||||
@@ -1079,6 +1083,11 @@ Fetch a list of articles rated more than 4 or published after "01/01/2018":
|
||||
}
|
||||
}
|
||||
|
||||
.. note::
|
||||
|
||||
The ``_or`` operator expects an array of expressions as input. See the :ref:`API reference <OrExp>` for details on
|
||||
the behaviour if an object is passed as input.
|
||||
|
||||
.. _nested_filter:
|
||||
|
||||
Filter nested objects
|
||||
@@ -1682,4 +1691,4 @@ Evaluation of **null** values in comparision expressions
|
||||
If in any comparision expression a ``null`` (or ``undefined``) value is passed, the expression currently gets
|
||||
reduced to ``{}`` (:ref:`TRUE expression <true_expression>`)
|
||||
|
||||
**For example**, the expression ``{ where: { _eq: null } }`` will be reduced to ``{ where: {} }``
|
||||
**For example**, the expression ``{ where: { _eq: null } }`` will be reduced to ``{ where: {} }``
|
||||
|
||||
Reference in New Issue
Block a user