Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add boolean expressions syntactic sugar notes in docs #3510

Merged
merged 8 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: {} }``