Skip to content

Commit

Permalink
add boolean expressions syntactic sugar notes in docs (#3510)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikinsk authored Dec 17, 2019
1 parent 7abe5dd commit deeae45
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
66 changes: 66 additions & 0 deletions docs/graphql/manual/api-reference/graphql-api/query.rst
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ BoolExp
AndExp_ | OrExp_ | NotExp_ | TrueExp_ | ColumnExp_
.. _AndExp:

AndExp
######

Expand All @@ -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
#####

Expand All @@ -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
######

Expand Down
11 changes: 10 additions & 1 deletion docs/graphql/manual/queries/query-filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: {} }``

0 comments on commit deeae45

Please sign in to comment.