forked from TryGhost/GQL
-
Notifications
You must be signed in to change notification settings - Fork 0
GQL Syntax
Laran Evans edited this page Mar 29, 2016
·
3 revisions
GQL Language Spec
A condition is a string which provides the property, operator and value in the form property:operatorvalue:
-
property- a path representing the key to filter on -
:- separator between property and an operator-value expression operator is optional, so:on its own is roughly=
Matches: [a-zA-Z_][a-zA-Z0-9_.]
- can contain only alpha-numeric characters and
_ - cannot contain whitespace
- must start with a letter
- supports . separated paths, E.g. author.name or posts.count
Filter expressions can be combined using the following:
-
+- represents and -
,- represents or -
(conditions)- overrides operator precedence by defining a clause
-
>- greater than operator -
>=- greater than or equals operator -
<- less than operator -
<=- less than or equals operator -
~- like operator
Can be one of the following:
- null
- true
- false
- a number (integer or decimal)
- a literal
-
- Any character string which follows these rules:
-
- Cannot contain any of these symbols:
,+unless they are escaped
- Cannot contain any of these symbols:
-
- Also cannot contain these symbols when inside an IN clause:
]unless they are escaped
- Also cannot contain these symbols when inside an IN clause:
-
- Literals can be date values in any format provided that the special characters
,+[]are properly escaped.
- Literals can be date values in any format provided that the special characters
- a string surrounded by single quotes
-
- Any character except a single quote
-
- Single quotes MUST be escaped
-
- Strings can be date values in any format provided that single quotes are properly escaped.
Conditions can be negated using ! before the property.
-
!- not operator
-
+- and symbol -
,- or symbol -
(- left parenthesis (operator precedence) -
)- right parenthesis (operator precedence) -
:- filter expression separator -
>- greater than operator -
>=- greater than or equals operator -
<- less than operator -
<=- less than or equals operator -
~- like operator -
[- left bracket (in operator) -
]- right bracket (in operator) -
'- single quote (string syntax)
- Whitespace is not permitted inside of a property.
- Whitespace is allowed inside both strings and literals though leading and trailing space is ignored.
- Everywhere else, whitespace is ignored and therefore becomes optional.
This allows for whitespace to be used to improve readability if necessary, as any of the following are equivalent and will be accepted.
featured:true+$having.posts_count:>10, tags:photo,tags:videofeatured:true + $having.posts_count:>10, tags:photo, tags:videofeatured: true + $having.posts_count: >10, tags: photo, tags: videofeatured: true + $having.posts_count :> 10, tags: photo, tags: video