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 set unique and index as true 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 nor last is specified, first defaults to DefaultQueryLimitSize (default: 100).
  • If both first and last are specified, an error is returned.
  • If first or last 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) and id to generate the cursor.
  • If an order is specified, the cursor is created using the specified field and id.

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)">&quot;data&quot;</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)">&quot;users&quot;</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)">&quot;pageInfo&quot;</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)">&quot;hasNextPage&quot;</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)">&quot;endCursor&quot;</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)">&quot;W3siZm...In1d&quot;</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)">&quot;edges&quot;</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)">&quot;node&quot;</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)">&quot;name&quot;</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)">&quot;user1&quot;</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)">&quot;node&quot;</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)">&quot;name&quot;</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)">&quot;user2&quot;</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)">&quot;node&quot;</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)">&quot;name&quot;</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)">&quot;user3&quot;</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)">&quot;W3siZm...In1d&quot;</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)">&quot;data&quot;</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)">&quot;users&quot;</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)">&quot;pageInfo&quot;</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)">&quot;hasNextPage&quot;</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)">&quot;endCursor&quot;</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)">&quot;W3siZm...In1d&quot;</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)">&quot;edges&quot;</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)">&quot;node&quot;</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)">&quot;name&quot;</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)">&quot;user4&quot;</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)">&quot;node&quot;</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)">&quot;name&quot;</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)">&quot;user5&quot;</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.

ArgumentDescription
directionDesc or Asc
fieldField 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 and PermissionItemInput values for read, update, and delete actions. PermissionItemInput has a PermitEnum field that can be either allow or deny. 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)">&amp;</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)">&quot;</span><span style="color: var(--shiki-token-string-expression)">Report number</span><span style="color: var(--shiki-color-text)">&quot;</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.