Auto-generated APIs
Based on the name of the schema, GraphQL APIs are automatically generated. Each query has fields defined in the schema. See fields section for details. The following generated queries and mutations are available for use:
Queries
<type_name>
: return a single resource based on the provided resource ID.<type_name>By
: return a single resource based on the unique field value.
To enable this query, you need to setunique
andindex
astrue
in the field settings. See Supporting fields for more details.<type_name>s
: return multiple resources based on a search query (query), pagination parameters, and a sorting parameter (order).<type_name>Permission
: return permissions set in the resource based on the provided resource ID.
Pagination
We support cursor pagination by default in TailorDB. This approach enables for more efficient data retrieval, especially for large datasets.
Cursor pagination uses cursors like after
and first
to fetch data relative to a specific point.
<span><span style="color: var(--shiki-token-keyword)">type</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-constant)">Query</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> users(</span></span>
<span><span style="color: var(--shiki-color-text)"> query: </span><span style="color: var(--shiki-token-constant)">UserQueryInput</span></span>
<span><span style="color: var(--shiki-color-text)"> order: </span><span style="color: var(--shiki-token-constant)">UserOrderInput</span></span>
<span><span style="color: var(--shiki-color-text)"> first: </span><span style="color: var(--shiki-token-constant)">Int</span></span>
<span><span style="color: var(--shiki-color-text)"> after: </span><span style="color: var(--shiki-token-constant)">String</span></span>
<span><span style="color: var(--shiki-color-text)"> last: </span><span style="color: var(--shiki-token-constant)">Int</span></span>
<span><span style="color: var(--shiki-color-text)"> before: </span><span style="color: var(--shiki-token-constant)">String</span></span>
<span><span style="color: var(--shiki-color-text)"> ): </span><span style="color: var(--shiki-token-constant)">UserConnection</span><span style="color: var(--shiki-token-keyword)">!</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span><span style="color: var(--shiki-token-keyword)">type</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-constant)">UserConnection</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> edges: [</span><span style="color: var(--shiki-token-constant)">UserEdge</span><span style="color: var(--shiki-token-keyword)">!</span><span style="color: var(--shiki-color-text)">]</span><span style="color: var(--shiki-token-keyword)">!</span></span>
<span><span style="color: var(--shiki-color-text)"> pageInfo: </span><span style="color: var(--shiki-token-constant)">PageInfo</span><span style="color: var(--shiki-token-keyword)">!</span></span>
<span><span style="color: var(--shiki-color-text)"> total: </span><span style="color: var(--shiki-token-constant)">Int</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span><span style="color: var(--shiki-token-keyword)">type</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-constant)">UserEdge</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> node: </span><span style="color: var(--shiki-token-constant)">User</span><span style="color: var(--shiki-token-keyword)">!</span></span>
<span><span style="color: var(--shiki-color-text)"> cursor: </span><span style="color: var(--shiki-token-constant)">String</span><span style="color: var(--shiki-token-keyword)">!</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span><span style="color: var(--shiki-token-keyword)">type</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-constant)">PageInfo</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> hasNextPage: </span><span style="color: var(--shiki-token-constant)">Boolean</span><span style="color: var(--shiki-token-keyword)">!</span></span>
<span><span style="color: var(--shiki-color-text)"> hasPreviousPage: </span><span style="color: var(--shiki-token-constant)">Boolean</span><span style="color: var(--shiki-token-keyword)">!</span></span>
<span><span style="color: var(--shiki-color-text)"> startCursor: </span><span style="color: var(--shiki-token-constant)">String</span></span>
<span><span style="color: var(--shiki-color-text)"> endCursor: </span><span style="color: var(--shiki-token-constant)">String</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>
The string input for after
or before
needs to be a base64-encoded representation of the cursor.
The number of records retrieved is determined by the first
or last
parameter:
- If neither
first
norlast
is specified,first
defaults toDefaultQueryLimitSize
(default: 100). - If both
first
andlast
are specified, an error is returned. - If
first
orlast
is less than 0 or greater than 1000, an error is returned.
The retrieval order of records is determined by the order
parameter:
- If no
order
is specified, the records will be retrieved in the order they were created, using_created
(an internal field) andid
to generate the cursor. - If an
order
is specified, the cursor is created using the specified field andid
.
Example Query
<span><span style="color: var(--shiki-token-keyword)">query</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-function)">users</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> users(</span></span>
<span><span style="color: var(--shiki-color-text)"> first: </span><span style="color: var(--shiki-token-constant)">3</span><span style="color: var(--shiki-color-text)">,</span></span>
<span><span style="color: var(--shiki-token-comment)"> # Without specifying after, retrieve the first 3 records</span></span>
<span><span style="color: var(--shiki-color-text)"> order: [{</span><span style="color: var(--shiki-token-string)">field</span><span style="color: var(--shiki-color-text)">: name, </span><span style="color: var(--shiki-token-string)">direction</span><span style="color: var(--shiki-color-text)">: Asc}]</span></span>
<span><span style="color: var(--shiki-color-text)"> ) {</span></span>
<span><span style="color: var(--shiki-color-text)"> pageInfo {</span></span>
<span><span style="color: var(--shiki-color-text)"> hasNextPage</span></span>
<span><span style="color: var(--shiki-color-text)"> endCursor</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> edges {</span></span>
<span><span style="color: var(--shiki-color-text)"> node {</span></span>
<span><span style="color: var(--shiki-color-text)"> name</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>
<span><span style="color: var(--shiki-color-text)">{</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"data"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"users"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"pageInfo"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"hasNextPage"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-constant)">true</span><span style="color: var(--shiki-token-punctuation)">,</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"endCursor"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string-expression)">"W3siZm...In1d"</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span><span style="color: var(--shiki-token-punctuation)">,</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"edges"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> [</span></span>
<span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"node"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"name"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string-expression)">"user1"</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span><span style="color: var(--shiki-token-punctuation)">,</span></span>
<span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"node"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"name"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string-expression)">"user2"</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span><span style="color: var(--shiki-token-punctuation)">,</span></span>
<span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"node"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"name"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string-expression)">"user3"</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> ]</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>
<span><span style="color: var(--shiki-token-keyword)">query</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-function)">users</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> users(</span></span>
<span><span style="color: var(--shiki-color-text)"> first: </span><span style="color: var(--shiki-token-constant)">3</span><span style="color: var(--shiki-color-text)">,</span></span>
<span><span style="color: var(--shiki-token-comment)"> # Specifying the endCursor from the previous response to retrieve the next 3 records.</span></span>
<span><span style="color: var(--shiki-color-text)"> after: </span><span style="color: var(--shiki-token-string-expression)">"W3siZm...In1d"</span></span>
<span><span style="color: var(--shiki-color-text)"> order: [{</span><span style="color: var(--shiki-token-string)">field</span><span style="color: var(--shiki-color-text)">: name, </span><span style="color: var(--shiki-token-string)">direction</span><span style="color: var(--shiki-color-text)">: Asc}]</span></span>
<span><span style="color: var(--shiki-color-text)"> ) {</span></span>
<span><span style="color: var(--shiki-color-text)"> pageInfo {</span></span>
<span><span style="color: var(--shiki-color-text)"> hasNextPage</span></span>
<span><span style="color: var(--shiki-color-text)"> endCursor</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> edges {</span></span>
<span><span style="color: var(--shiki-color-text)"> node {</span></span>
<span><span style="color: var(--shiki-color-text)"> name</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>
<span><span style="color: var(--shiki-color-text)">{</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"data"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"users"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"pageInfo"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-comment)">// Since hasNextPage is false, there is no point in retrieving more records.</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"hasNextPage"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-constant)">false</span><span style="color: var(--shiki-token-punctuation)">,</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"endCursor"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string-expression)">"W3siZm...In1d"</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span><span style="color: var(--shiki-token-punctuation)">,</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"edges"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> [</span></span>
<span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"node"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"name"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string-expression)">"user4"</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span><span style="color: var(--shiki-token-punctuation)">,</span></span>
<span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"node"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">"name"</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string-expression)">"user5"</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> ]</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>
Sorting
You can use the order: [QueryNameOrderInput]
argument to sort the results of the query.
The argument accepts an array of QueryNameOrderInput values, each of which will be evaluated in the order specified in the array.
Argument | Description |
---|---|
direction | Desc or Asc |
field | Field name as the enumeration value |
Filtering
Refer to Filters guide.
Mutations
Create, Update and Delete
create<type_name>
: create the resource based on the values provided for each field.update<type_name>
: update the resource based on the provided resource ID and the values provided for each field.delete<type_name>
: delete the resource based on the provided resource ID.
Change Permission
change<type_name>
: change the permission of the resource based on the provided resource ID andPermissionItemInput
values for read, update, and delete actions.PermissionItemInput
has aPermitEnum
field that can be eitherallow
ordeny
. See Permission for more details.
Example
As the example, if you specify this Report
schema, the following queries and mutations API will be automatically generated based on the schema.
<span><span style="color: var(--shiki-color-text)">Report: tailordb.#Type </span><span style="color: var(--shiki-token-keyword)">&</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> Fields: {</span></span>
<span><span style="color: var(--shiki-color-text)"> reportNo: {</span></span>
<span><span style="color: var(--shiki-color-text)"> Type: tailordb.#TypeInt</span></span>
<span><span style="color: var(--shiki-color-text)"> Description: </span><span style="color: var(--shiki-color-text)">"</span><span style="color: var(--shiki-token-string-expression)">Report number</span><span style="color: var(--shiki-color-text)">"</span></span>
<span><span style="color: var(--shiki-color-text)"> Index: </span><span style="color: var(--shiki-token-constant)">true</span></span>
<span><span style="color: var(--shiki-color-text)"> Unique: </span><span style="color: var(--shiki-token-constant)">true</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> ...</span></span>
<span><span style="color: var(--shiki-color-text)"> }</span></span>
<span><span style="color: var(--shiki-color-text)"> ...</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>
Besides basic CRUD operations, Aggregation, Bulk upsert and more available as Advanced APIs.