2018-09-11 14:11:24 +03:00
.. title :: API Reference - Query/Subscription
API Reference - Query/Subscription
==================================
Query/Subscription syntax
-------------------------
.. code-block :: none
query|subscription [<op-name> ] {
object [([argument])]{
object-fields
}
}
.. list-table ::
:header-rows: 1
* - Key
- Required
- Schema
- Description
* - op-name
- false
- Value
- Name query/subscription for observability
* - object
- true
- Object_
- Name of the table/object
* - argument
- false
- Argument_
2018-10-04 07:09:47 +03:00
- One or more of filter criteria, instructions for sort order or pagination
2018-09-11 14:11:24 +03:00
**E.g. QUERY** :
.. code-block :: graphql
query {
2018-10-26 14:57:33 +03:00
author(where: {articles: {rating: {_gte: 4}}} order_by: {name: asc}) {
2018-09-11 14:11:24 +03:00
id
name
}
}
**E.g. SUBSCRIPTION** :
.. code-block :: graphql
subscription {
2018-10-26 14:57:33 +03:00
author(where: {articles: rating: {_gte: 4}}} order_by: {name: asc}) {
2018-09-11 14:11:24 +03:00
id
name
}
}
.. note ::
2018-10-26 14:57:33 +03:00
2018-09-11 14:11:24 +03:00
For more examples and details of usage, please see :doc: `this <../queries/index>` .
Syntax definitions
------------------
.. _Object:
Object
^^^^^^
.. code-block :: none
object-name {
field1
field2
..
nested object1
nested object2
..
}
E.g.
.. code-block :: graphql
author {
id # scalar field
name # scalar field
article { # nested object
title
}
}
.. _Argument:
Argument
^^^^^^^^
.. parsed-literal ::
WhereExp_ | OrderByExp_ | PaginationExp_
.. _WhereExp:
WhereExp
***** ***
.. parsed-literal ::
where: BoolExp_
.. _BoolExp:
BoolExp
"""""""
.. parsed-literal ::
AndExp_ | OrExp_ | NotExp_ | ColumnExp_
2018-10-31 16:49:29 +03:00
.. _AndExp:
2018-09-11 14:11:24 +03:00
AndExp
######
.. parsed-literal ::
{
_and: [BoolExp_]
}
2018-10-31 16:49:29 +03:00
.. _OrExp:
2018-09-11 14:11:24 +03:00
OrExp
#####
.. parsed-literal ::
{
_or: [BoolExp_]
}
2018-10-31 16:49:29 +03:00
.. _NotExp:
2018-09-11 14:11:24 +03:00
NotExp
######
.. parsed-literal ::
{
_not: BoolExp_
}
ColumnExp
#########
.. parsed-literal ::
{
field-name : {Operator_: Value }
}
2018-10-31 16:49:29 +03:00
.. _Operator:
2018-09-11 14:11:24 +03:00
Operator
########
Generic operators (all column types except json, jsonb) :
- `` _eq ``
2018-09-20 12:51:27 +03:00
- `` _neq ``
2018-09-11 14:11:24 +03:00
- `` _in ``
- `` _nin ``
- `` _gt ``
- `` _lt ``
- `` _gte ``
- `` _lte ``
2018-09-20 12:51:27 +03:00
JSONB operators:
2018-09-11 14:11:24 +03:00
2018-09-20 12:51:27 +03:00
.. list-table ::
:header-rows: 1
* - Operator
- PostgreSQL equivalent
* - `` _contains ``
- `` @> ``
* - `` _contained_in ``
- `` <@ ``
* - `` _has_key ``
- `` ? ``
* - `` _has_keys_any ``
- `` ?| ``
* - `` _has_keys_all ``
- `` ?& ``
2018-10-04 07:09:47 +03:00
(For more details on what these operators do, refer to `Postgres docs <https://www.postgresql.org/docs/current/static/functions-json.html#FUNCTIONS-JSONB-OP-TABLE> `_ .)
2018-09-11 14:11:24 +03:00
Text related operators :
- `` _like ``
- `` _nlike ``
- `` _ilike ``
- `` _nilike ``
- `` _similar ``
- `` _nsimilar ``
Checking for `` null `` values :
- `` _is_null `` (takes true/false as values)
2018-09-20 12:51:27 +03:00
2018-09-11 14:11:24 +03:00
.. _OrderByExp:
OrderByExp
***** *****
.. parsed-literal ::
2018-10-26 14:57:33 +03:00
order_by: (TableOrderBy_ | [ TableOrderBy_ ])
2018-09-11 14:11:24 +03:00
E.g.
2018-10-26 14:57:33 +03:00
.. parsed-literal ::
2018-09-11 14:11:24 +03:00
2018-10-26 14:57:33 +03:00
order_by: {id: desc}
2018-09-11 14:11:24 +03:00
or
2018-10-26 14:57:33 +03:00
.. parsed-literal ::
order_by: [{id: desc}, {author: {id: asc}}]
.. _TableOrderBy:
TableOrderBy
2018-11-06 11:38:40 +03:00
***** ***** **
2018-10-26 14:57:33 +03:00
For columns:
.. parsed-literal ::
{column: OrderByEnum_}
For object relations:
.. parsed-literal ::
{relation-name: TableOrderBy_}
E.g.
Order by type for "article" table:
2018-09-11 14:11:24 +03:00
.. code-block :: graphql
2018-10-26 14:57:33 +03:00
input article_order_by {
id: order_by
title: order_by
content: order_by
author_id: order_by
#order by using "author" object relationship columns
author: author_order_by
}
2018-09-11 14:11:24 +03:00
2018-10-26 14:57:33 +03:00
.. _OrderByEnum:
2018-09-11 14:11:24 +03:00
2018-10-26 14:57:33 +03:00
OrderByEnum
***** ***** *
2018-09-11 14:11:24 +03:00
2018-10-26 14:57:33 +03:00
.. code-block :: graphql
#the order_by enum type
enum order_by {
#in the ascending order
asc
#in the descending order
desc
#in the ascending order, nulls first
asc_nulls_first
#in the descending order, nulls first
desc_nulls_first
}
2018-09-11 14:11:24 +03:00
.. _PaginationExp:
PaginationExp
***** ***** ***
.. parsed-literal ::
2018-10-26 05:59:36 +03:00
limit: Integer
[offset: Integer]