GraphQL

As of version 3.0, Structr supports a read-only version of GraphQL queries.

Access
The GraphQL endpoint is available via HTTP using the following URL:

http://host:port/structr/graphql

Queries can be sent to the endpoint using either GET with a request parameter named query, or via POST which is the recommended way.

Further reading
For GraphQL reference documentation, please refer to http://graphql.org/learn/.

API
A simple query looks like this

{ Group { id, name, type, members { id, name, type } } }

All collection fields support the following keys:

_pageSize: int
_first: int
_page: int
_sort: string
_desc: boolean

The keyword _first is just a convenience attribute for _pageSize.

{ Group(_pageSize: 2) { name, members(_pageSize: 2, _page: 2) { name }}}

The toplevel selections support simple equals queries:

{ Principal(name: "Axel") { name } }

The same queries but much more powerful can be applied on field level

{ Principal { name(_equals: "Axel") } }
{ Group(_pageSize: 1) { name }, Principal(_pageSize: 2, _page: 2) { name(_contains: "i") } }

String fields support additional keys:

_equals: <property type>
_contains: <property type>
{ Principal { name(_contains: "a", _contains: "l", _conj: "and") } }

The _conj keyword is short for “conjuction”, which specifies the type of conjunction (AND, OR or NOT)

{ Group { members { name(_contains: "k", _contains: "l", _conj: "and") }}}
{ Group { members { name(_contains: "k", _contains: "l", _conj: "or") }}}

Related node fields support selection by object like this:

{ MailTemplate { id, type, text(_contains: "2"), owner(_equals: { name: "Axel"}) { name } }}
About this article
Last change 2019-11-08
Topics