2019-02-06 09:39:36 +03:00
API Reference - Query / Subscription
====================================
2018-09-11 14:11:24 +03:00
2018-12-03 15:12:24 +03:00
.. contents :: Table of contents
:backlinks: none
:depth: 3
:local:
2018-09-11 14:11:24 +03:00
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
^^^^^^
2019-02-06 09:39:36 +03:00
.. parsed-literal ::
SimpleObject_ | AggregateObject_
.. _SimpleObject:
2018-12-17 14:58:29 +03:00
2018-12-03 15:12:24 +03:00
Simple Object
***** ***** ***
2018-11-15 14:43:03 +03:00
2018-09-11 14:11:24 +03:00
.. code-block :: none
object-name {
field1
field2
2019-03-25 16:45:35 +03:00
json_field[(path: String)]
2018-09-11 14:11:24 +03:00
..
nested object1
nested object2
2018-11-15 14:43:03 +03:00
aggregate nested object1
2018-09-11 14:11:24 +03:00
..
}
2019-03-25 16:45:35 +03:00
.. list-table ::
:header-rows: 1
* - Key
- Required
- Schema
- Description
* - path
- false
- Value
- `` path `` argument of `` json `` /`` jsonb `` follows simple `JSONPath specification <https://github.com/json-path/JsonPath> `_ . However, prefix symbol `` $. `` is optional.
2018-09-11 14:11:24 +03:00
E.g.
.. code-block :: graphql
author {
2019-03-25 16:45:35 +03:00
id # scalar integer field
name # scalar text field
address(path: "$.city") # scalar JSON field -> property
address(path: "city") # scalar JSON field -> property; '$.' prefix is optional
contacts(path: "[0]") # scalar JSON field -> array_item
contacts(path: "[0].phone") # scalar JSON field -> array_item_property
2018-11-15 14:43:03 +03:00
article { # nested object
2018-09-11 14:11:24 +03:00
title
}
2019-03-25 16:45:35 +03:00
2018-11-15 14:43:03 +03:00
article_aggregate { # aggregate nested object
aggregate {
count
}
nodes {
title
}
}
2018-09-11 14:11:24 +03:00
}
2019-02-06 09:39:36 +03:00
.. _AggregateObject:
2018-12-17 14:58:29 +03:00
2018-12-03 15:12:24 +03:00
Aggregate Object
***** ***** ***** *
2018-11-15 14:43:03 +03:00
.. code-block :: none
object-name_aggregate {
aggregate {
count
sum {
field
..
}
avg {
field
..
}
stddev {
field
..
}
stddev_samp {
field
..
}
stddev_pop {
field
..
}
variance {
field
..
}
var_samp {
field
..
}
var_pop {
field
..
}
max {
field
..
}
min {
field
..
}
nodes {
field1
field2
..
nested object1
nested object2
aggregate nested object1
..
}
}
(For more details on aggregate functions, refer to `Postgres docs <https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-AGGREGATE-STATISTICS-TABLE> `__ .)
E.g.
.. code-block :: graphql
author_aggregate {
aggregate {
count # total count
sum {
id # sum aggregate on id
}
avg {
id # avg aggregate on id
}
stddev {
id # stddev aggregate on id
}
stddev_samp {
id # stddev_samp aggregate on id
}
stddev_pop {
id # stddev_pop aggregate on id
}
variance {
id # variance aggregate on id
}
var_samp {
id # var_samp aggregate on id
}
var_pop {
id # var_pop aggregate on id
}
max {
id # max aggregate on id
}
min {
id # min aggregate on id
}
}
nodes { # objects
id # scalar field
name # scalar field
article { # nested object
title
}
2019-02-06 09:39:36 +03:00
article_aggregate { # aggregate nested object
2018-11-15 14:43:03 +03:00
aggregate {
count
}
nodes {
title
}
}
}
}
2018-09-11 14:11:24 +03:00
Argument
^^^^^^^^
.. parsed-literal ::
2018-11-23 04:53:56 +03:00
DistinctOnExp_ | WhereExp_ | OrderByExp_ | PaginationExp_
.. _DistinctOnExp:
DistinctOnExp
2018-12-03 15:12:24 +03:00
***** ***** ***
2018-11-23 04:53:56 +03:00
.. parsed-literal ::
distinct_on: [ TableSelectColumnEnum_ ]
TableSelectColumnEnum
"""""""""""""""""""""
.. code-block :: graphql
#example table_select_column enum for "article" table
enum article_select_column {
id
title
content
author_id
is_published
}
2018-09-11 14:11:24 +03:00
.. _WhereExp:
WhereExp
***** ***
.. parsed-literal ::
where: BoolExp_
BoolExp
"""""""
.. parsed-literal ::
AndExp_ | OrExp_ | NotExp_ | ColumnExp_
AndExp
######
.. parsed-literal ::
{
_and: [BoolExp_]
}
OrExp
#####
.. parsed-literal ::
{
_or: [BoolExp_]
}
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
########
2019-01-21 12:20:14 +03:00
**Generic operators (all column types except json, jsonb):**
2018-09-11 14:11:24 +03:00
- `` _eq ``
2018-09-20 12:51:27 +03:00
- `` _neq ``
2018-09-11 14:11:24 +03:00
- `` _in ``
- `` _nin ``
- `` _gt ``
- `` _lt ``
- `` _gte ``
- `` _lte ``
2019-02-06 09:39:36 +03:00
**Text related operators:**
- `` _like ``
- `` _nlike ``
- `` _ilike ``
- `` _nilike ``
- `` _similar ``
- `` _nsimilar ``
**Checking for NULL values:**
- `` _is_null `` (takes true/false as values)
2019-01-21 12:20:14 +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-11-15 14:43:03 +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
2019-01-21 12:20:14 +03:00
**PostGIS related operators on GEOMETRY columns:**
2019-01-17 09:21:38 +03:00
.. list-table ::
:header-rows: 1
* - Operator
- PostGIS equivalent
* - `` _st_contains ``
- `` ST_Contains ``
* - `` _st_crosses ``
- `` ST_Crosses ``
* - `` _st_equals ``
- `` ST_Equals ``
* - `` _st_intersects ``
- `` ST_Intersects ``
* - `` _st_overlaps ``
- `` ST_Overlaps ``
* - `` _st_touches ``
- `` ST_Touches ``
* - `` _st_within ``
- `` ST_Within ``
* - `` _st_d_within ``
- `` ST_DWithin ``
(For more details on what these operators do, refer to `PostGIS docs <http://postgis.net/workshops/postgis-intro/spatial_relationships.html> `__ .)
2019-01-21 12:20:14 +03:00
.. note ::
2019-02-06 09:39:36 +03:00
- All operators take a JSON representation of `` geometry/geography `` values as input value.
- Input value for `` _st_d_within `` operator is an object:
2019-01-17 09:21:38 +03:00
2019-02-06 09:39:36 +03:00
.. parsed-literal ::
2019-01-17 09:21:38 +03:00
{
field-name : {_st_d_within: {distance: Float, from: Value} }
}
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}}]
2018-12-12 15:58:39 +03:00
or
.. parsed-literal ::
order_by: {articles_aggregate: {count: asc}}
2018-10-26 14:57:33 +03:00
TableOrderBy
2019-02-06 09:39:36 +03:00
""""""""""""
2018-10-26 14:57:33 +03:00
For columns:
.. parsed-literal ::
{column: OrderByEnum_}
For object relations:
.. parsed-literal ::
{relation-name: TableOrderBy_}
2018-12-12 15:58:39 +03:00
For array relations aggregate:
.. parsed-literal ::
{relation-name_aggregate: AggregateOrderBy_}
2018-10-26 14:57:33 +03:00
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-12-12 15:58:39 +03:00
#order by using "likes" array relationship aggregates
likes_aggregate: likes_aggregate_order_by
2018-10-26 14:57:33 +03:00
}
2018-09-11 14:11:24 +03:00
2018-10-26 14:57:33 +03:00
OrderByEnum
2019-02-06 09:39:36 +03:00
###########
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 {
2018-11-22 07:58:18 +03:00
#in the ascending order, nulls last
2018-10-26 14:57:33 +03:00
asc
2018-11-22 07:58:18 +03:00
#in the ascending order, nulls last
asc_nulls_last
2018-10-26 14:57:33 +03:00
#in the ascending order, nulls first
asc_nulls_first
#in the descending order, nulls first
2018-11-22 07:58:18 +03:00
desc
#in the descending order, nulls first
2018-10-26 14:57:33 +03:00
desc_nulls_first
2018-11-22 07:58:18 +03:00
#in the descending order, nulls last
desc_nulls_last
2018-10-26 14:57:33 +03:00
}
2018-09-11 14:11:24 +03:00
2019-03-25 16:45:35 +03:00
AggregateOrderBy
2019-02-06 09:39:36 +03:00
################
Count aggregate
.. parsed-literal ::
{count: OrderByEnum_}
Operation aggregate
.. parsed-literal ::
{op_name: TableAggOpOrderBy_}
Available operations are `` sum `` , `` avg `` , `` max `` , `` min `` , `` stddev `` , `` stddev_samp `` ,
`` stddev_pop `` , `` variance `` , `` var_samp `` and `` var_pop ``
TableAggOpOrderBy
&&&&&&&&&&&&&&&&&
.. parsed-literal ::
{column: OrderByEnum_}
2018-09-11 14:11:24 +03:00
.. _PaginationExp:
PaginationExp
***** ***** ***
.. parsed-literal ::
2018-10-26 05:59:36 +03:00
limit: Integer
[offset: Integer]