Advanced Settings

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

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

  • Directives
  • Extends

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>