Advanced Settings

Enabling extra features in settings field allows you to generate additional GraphQL queries. These features include:

  • Aggregating values
  • Bulk upsert
  • Versioning data
  • Multiple indexes
  • Plural form for uncountable nouns

Also, we can utilize the following advanced GraphQL schema configuration to optimize GraphQL queries.

  • Directives
  • Extends

Aggregation

Aggregation queries enable the summarization and analysis of large datasets.
Through leveraging these aggregation queries, you can quickly aggregate your records to identify trends, relationships, and anomalies, which provide insights for your decision-making.

You can enable the Aggregation setting for your type, which will automatically generate the aggregate query type: aggregate<type_name>s.
Available operations are count, max, min, sum, avg, totalSize, and groupBy.

Example

<span><span style="color: var(--shiki-color-text)">Payroll: 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)">  Description: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">payroll model</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">  TypePermission:  permissions.employee</span></span>
<span><span style="color: var(--shiki-color-text)">  Settings: {</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-comment)">// enable Aggregation</span></span>
<span><span style="color: var(--shiki-color-text)">    Aggregation: </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)">  Fields: {</span></span>
<span><span style="color: var(--shiki-color-text)">    name: {</span></span>
<span><span style="color: var(--shiki-color-text)">      Type:        tailordb.#TypeString</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)">name.</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">    }</span></span>
<span><span style="color: var(--shiki-color-text)">    paidAt: {</span></span>
<span><span style="color: var(--shiki-color-text)">      Type:        tailordb.#TypeDatetime</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)">paidAt</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">      Required:    </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)">    paidAmount: {</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)">paidAmount</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">      Required:  </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)">    payrollType: {</span></span>
<span><span style="color: var(--shiki-color-text)">      Type:        tailordb.#TypeEnum</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)">paidType</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">      Required:     </span><span style="color: var(--shiki-token-constant)">true</span></span>
<span><span style="color: var(--shiki-color-text)">      AllowedValues: [</span></span>
<span><span style="color: var(--shiki-color-text)">        {Value: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">PAID</span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-punctuation)">,</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)">PAID type</span><span style="color: var(--shiki-color-text)">&quot;</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)">        {Value: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">UNPAID</span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-punctuation)">,</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)">UNPAID type</span><span style="color: var(--shiki-color-text)">&quot;</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>
<span><span style="color: var(--shiki-color-text)">    payrollCode: {</span></span>
<span><span style="color: var(--shiki-color-text)">      Type:        tailordb.#TypeString</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)">payrollCode</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">    }</span></span>
<span><span style="color: var(--shiki-color-text)">    customerID: {</span></span>
<span><span style="color: var(--shiki-color-text)">      Type:        tailordb.#TypeUUID</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)">customerID</span><span style="color: var(--shiki-color-text)">&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>

Tailor DB auto-generates aggregatePayrolls, allowing you to quickly retrieve summarized results for Payroll.
Based on the payroll type, here's the sample query to aggregate the payroll data:

<span><span style="color: var(--shiki-token-keyword)">query</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)">  aggregatePayrolls {</span></span>
<span><span style="color: var(--shiki-color-text)">    max {</span></span>
<span><span style="color: var(--shiki-color-text)">      paidAmount</span></span>
<span><span style="color: var(--shiki-color-text)">    }</span></span>
<span><span style="color: var(--shiki-color-text)">    sum {</span></span>
<span><span style="color: var(--shiki-color-text)">      paidAmount</span></span>
<span><span style="color: var(--shiki-color-text)">    }</span></span>
<span><span style="color: var(--shiki-color-text)">    min {</span></span>
<span><span style="color: var(--shiki-color-text)">      paidAmount</span></span>
<span><span style="color: var(--shiki-color-text)">    }</span></span>
<span><span style="color: var(--shiki-color-text)">    avg {</span></span>
<span><span style="color: var(--shiki-color-text)">      paidAmount</span></span>
<span><span style="color: var(--shiki-color-text)">    }</span></span>
<span><span style="color: var(--shiki-color-text)">    count {</span></span>
<span><span style="color: var(--shiki-color-text)">      name</span></span>
<span><span style="color: var(--shiki-color-text)">      toHour {</span></span>
<span><span style="color: var(--shiki-color-text)">        paidAt</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)">    totalSize</span></span>
<span><span style="color: var(--shiki-color-text)">    groupBy {</span></span>
<span><span style="color: var(--shiki-color-text)">      toDay {</span></span>
<span><span style="color: var(--shiki-color-text)">        paidAt</span></span>
<span><span style="color: var(--shiki-color-text)">      }</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>

In the [PayrollsAggregationResult] type, you can specify how you aggregate the data by using groupBy.
Other fields such as count and sum will return results based on the grouping specified in groupBy.
However totalSize always returns the total number of records regardless of the grouping.

The calculation fields count, sum min and max will be applicable only for the Integer and Float types.
Besides, grouping by time windows such as toDay and toHour will be applicable only for the Datetime and Date types.

Bulk Upsert

Bulk Upsert queries enable inserting or updating large amounts of resources with a single query. We can enable the bulkUpsert setting for your type, which will automatically generate the bulk upsert query type: bulkUpsert<type_name>s.

<span><span style="color: var(--shiki-color-text)">Document: 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)">  Description: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">Document model</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">  Settings: {</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-comment)">// ...</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-comment)">// enable bulkupsert</span></span>
<span><span style="color: var(--shiki-color-text)">    BulkUpsert: </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>

Tailor DB auto-generates bulkUpsertDocuments, allowing you to quickly bulk upsert data for Document. Use the following query to upsert existing document resources:

<span><span style="color: var(--shiki-token-keyword)">mutation</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)">  bulkUpsertDocuments(</span></span>
<span><span style="color: var(--shiki-color-text)">    input: [</span></span>
<span><span style="color: var(--shiki-color-text)">      { </span><span style="color: var(--shiki-token-string)">id</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-string-expression)">&quot;&lt;resource_uuid_1&gt;&quot;</span><span style="color: var(--shiki-color-text)">, </span><span style="color: var(--shiki-token-string)">documentStatus</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-string-expression)">&quot;documentToUpdate1&quot;</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-string)">id</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-string-expression)">&quot;&lt;resource_uuid_2&gt;&quot;</span><span style="color: var(--shiki-color-text)">, </span><span style="color: var(--shiki-token-string)">documentStatus</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-string-expression)">&quot;documentToUpdate2&quot;</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>

If the input contains existing IDs, the data properties will be updated for those inputs. New data records will be created if the ID does not exist, is null, or is not passed as an input property.

Here are examples of queries for creating new records in Tailor DB when using bulk upsert.

<span><span style="color: var(--shiki-token-keyword)">mutation</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)">  bulkUpsertDocuments(</span></span>
<span><span style="color: var(--shiki-color-text)">    input: [</span></span>
<span><span style="color: var(--shiki-color-text)">      { </span><span style="color: var(--shiki-token-string)">id</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-constant)">null</span><span style="color: var(--shiki-color-text)">, </span><span style="color: var(--shiki-token-string)">documentStatus</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-string-expression)">&quot;createsNewDocument1&quot;</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-string)">id</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-constant)">null</span><span style="color: var(--shiki-color-text)">, </span><span style="color: var(--shiki-token-string)">documentStatus</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-string-expression)">&quot;createsNewDocument2&quot;</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)">mutation</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)">  bulkUpsertDocuments(</span></span>
<span><span style="color: var(--shiki-color-text)">    input: [</span></span>
<span><span style="color: var(--shiki-color-text)">      { </span><span style="color: var(--shiki-token-string)">documentStatus</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-string-expression)">&quot;createsNewDocument1&quot;</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-string)">documentStatus</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-string-expression)">&quot;createsNewDocument2&quot;</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>

The maximum number of items that can be included in a single bulk upsert operation is 100.

Versioning

The versioning allows the tracking changes to your data, providing visibility and control over your data's evolution. This can be useful for application that require versioning of their data. We can enable the versioning setting for your type, which will automatically generate version and versions fields.

<span><span style="color: var(--shiki-color-text)">Payroll: 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)">  Description: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">Payroll information</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">  Settings: {</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-comment)">// ...</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-comment)">// enable Versioning</span></span>
<span><span style="color: var(--shiki-color-text)">    Versioning: </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>

Multiple Indexes

The Indexes field enables the definition of multiple indexes for a given type.
Additionally, it facilitates the establishment of a uniqueness constraint across multiple fields.
Such functionality is particularly beneficial for applications that necessitate the utilization of several indexes to manage their data efficiently.

For instance, consider the definition of the payRollCompositeKey index as follows:

<span><span style="color: var(--shiki-color-text)">Payroll: 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)">  Description: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">Payroll information</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">  Settings: {</span></span>
<span><span style="color: var(--shiki-color-text)">    Indexes: {</span></span>
<span><span style="color: var(--shiki-color-text)">      payRollCompositeKey: {</span></span>
<span><span style="color: var(--shiki-color-text)">        FieldNames: [</span></span>
<span><span style="color: var(--shiki-color-text)">          </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">customerID</span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-punctuation)">,</span></span>
<span><span style="color: var(--shiki-color-text)">          </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">payrollCode</span><span style="color: var(--shiki-color-text)">&quot;</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)">        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>

Within the Indexes configuration, one can specify the name of the composite index key using FieldNames, which indicates the fields to be included in the index.
In the provided example, we have designated the name payRollCompositeKey; however, the naming is flexible and can be changed as you like.

Furthermore, the Unique attribute specifies the constraint for multiple fields to be unique.
Here, it signifies that each customerID and payrollCode pairing must be distinct within the Payroll type, thereby preventing duplicate entries in the dataset.

Caveat: Enum type is not supported for the multiple indexes field.

Plural form for uncountable nouns

The PluralForm field accepts the plural form for an uncountable noun type in your Tailor DB. This setting is necessary to access individual records when the type name is an uncountable noun.

For example, to create type userData in the Tailor DB, configure the PluralForm in the settings as the following:

<span><span style="color: var(--shiki-color-text)">UserData: 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)">  Name:        </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">UserData</span><span style="color: var(--shiki-color-text)">&quot;</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)">User Data Model</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">  Settings: {</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-comment)">// configure PluralForm</span></span>
<span><span style="color: var(--shiki-color-text)">    PluralForm: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">UserDataList</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<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)">    name: {</span></span>
<span><span style="color: var(--shiki-color-text)">      Type:        tailordb.#TypeString</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)">Name of the user.</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">    }</span></span>
<span><span style="color: var(--shiki-color-text)">    createdAt: tailordb.CreatedAtField</span></span>
<span><span style="color: var(--shiki-color-text)">    updatedAt: tailordb.UpdatedAtField</span></span>
<span><span style="color: var(--shiki-color-text)">  }</span></span>
<span></span>
<span><span style="color: var(--shiki-color-text)">  TypePermission: permissions.editorAccess</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>
<span></span>

The following query retrieves the collection:

<span><span style="color: var(--shiki-token-keyword)">query</span><span style="color: var(--shiki-color-text)">{</span></span>
<span><span style="color: var(--shiki-color-text)">  UserDataList{</span></span>
<span><span style="color: var(--shiki-color-text)">    collection {</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>

Here is the query to retrieve individual records of the UserData type:

<span><span style="color: var(--shiki-token-keyword)">query</span><span style="color: var(--shiki-color-text)">{</span></span>
<span><span style="color: var(--shiki-color-text)">  userData(id:&lt;userDataId&gt;){</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>

Directives

Directive is a GraphQL concept, that provides a way to add additional instructions to GraphQL queries without having to modify the schema. This allows developers to use GraphQL to access the same data in different ways without having to change the underlying data structure. The Directives field holds a map structure data, where the key is directive name and the value is a map of arguments defined in the Args key.

For example, we can define the directive of @key(fields: "id") as the following:

<span><span style="color: var(--shiki-token-comment)">// enable directives</span></span>
<span><span style="color: var(--shiki-color-text)">Directives:  [{</span></span>
<span><span style="color: var(--shiki-color-text)">	Name: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">key</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">	Args: [</span></span>
<span><span style="color: var(--shiki-color-text)">    {</span></span>
<span><span style="color: var(--shiki-color-text)">      name:  </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">fields</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">      value: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">id</span><span style="color: var(--shiki-color-text)">&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>
<span><span style="color: var(--shiki-color-text)">}]</span></span>
<span></span>

See GraphQL Directives for more details.

Extends

The Extends option enables the extension of the types defined in other sub-graphs, like StateFlow. With this option enabled, CRUD GraphQL queries become available in Tailor DB. To make this work, the directive of @key(fields: "id") must be defined.

For example, if we want to extend State resource in StateFlow, we can define the extend and directives in the schema as follows: This will generate createExtendState, updateExtendState, deleteExtendState, and changeExtendState API.

<span><span style="color: var(--shiki-token-comment)">// example of state.cue enabling extends</span></span>
<span><span style="color: var(--shiki-color-text)">State: 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)">  </span><span style="color: var(--shiki-token-comment)">// ...</span></span>
<span><span style="color: var(--shiki-color-text)">  </span><span style="color: var(--shiki-token-comment)">// Set true for extends setting</span></span>
<span><span style="color: var(--shiki-color-text)">  Extends: </span><span style="color: var(--shiki-token-constant)">true</span></span>
<span><span style="color: var(--shiki-color-text)">  </span><span style="color: var(--shiki-token-comment)">// You must define @key(fields: &quot;id&quot;) directive as follows</span></span>
<span><span style="color: var(--shiki-color-text)">  Directives:  [{</span></span>
<span><span style="color: var(--shiki-color-text)">    Name: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">key</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">    Args: [</span></span>
<span><span style="color: var(--shiki-color-text)">      {</span></span>
<span><span style="color: var(--shiki-color-text)">        name:  </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">fields</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">        value: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">id</span><span style="color: var(--shiki-color-text)">&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>
<span><span style="color: var(--shiki-color-text)">  }]</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>