Skip to content
Laran Evans edited this page Mar 29, 2016 · 3 revisions

GQL Language Spec

Syntax

Condition

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 =

Property

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

Comparison Operator

  • > - greater than operator
  • >= - greater than or equals operator
  • < - less than operator
  • <= - less than or equals operator
  • ~ - like operator

Value

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
    • Also cannot contain these symbols when inside an IN clause: ] unless they are escaped
    • Literals can be date values in any format provided that the special characters ,+[] are properly escaped.
  • 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.

Negative conditions

Conditions can be negated using ! before the property.

  • ! - not operator

Special characters

  • + - 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 rules

  • 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:video
  • featured:true + $having.posts_count:>10, tags:photo, tags:video
  • featured: true + $having.posts_count: >10, tags: photo, tags: video
  • featured: true + $having.posts_count :> 10, tags: photo, tags: video

Clone this wiki locally