Links

Querying a SDTF graph

Learn more about how to query your SDTF token graph.

Introduction

Your token system can be more complex than it seems. You will often need to interact with your token graph to transform a specific set of design tokens within a Specify configuration.
This article will help you understand how you can query your token graph to select a specific set of tokens.

Compatible parsers

Query structure

Every Query holds a single a where property being an object, to select one branch of the graph, or an array of objects, to select many branches of the graph (OR statement).
Type Query = { where: Where | Array<Where> }
The where property splits in 3 kinds: token, group, collection - offering a dedicated set of options to match against the given kind.
The name property accepts a RegExp for a value. These resources will help you debug your regular expressions:

Where Token

type WhereToken = {
token:
| string
| {
name?: string;
description?: string?;
}
select:
| true
| {
token?: boolean;
parents?:
| true
| {
groups?: true;
collections?: true;
}
}
}

Where Group

type WhereGroup = {
group: string;
select:
| true
| {
group?: boolean;
parents?:
| true
| {
groups?: true;
collections?: true;
}
children:
| true
| {
groups?: true;
collections?: true;
tokens?: true;
}
}
}

Where Collection

type WhereCollection = {
collection: string;
select:
| true
| {
collection?: boolean;
parents?:
| true
| {
groups?: true;
}
children:
| true
| {
groups?: true;
tokens?: true;
}
}
}

Use cases

Select tokens from a specific collection

.specifyrc.json
1
{
2
"version": "2",
3
"repository": "@organization/repository",
4
"personalAccessToken": "<your-personal-access-token>",
5
"rules": [
6
{
7
"name": "Get tokens from collection named 'Colors'",
8
"parsers": [
9
{
10
"name": "filter",
11
"options": {
12
"query": {
13
"where": {
14
"collection": "^Colors$",
15
"select": {
16
"parents": true,
17
"children": true
18
}
19
}
20
}
21
}
22
}
23
]
24
}
25
]
26
}

Select tokens from several collections matching a naming pattern

.specifyrc.json
1
{
2
"version": "2",
3
"repository": "@organization/repository",
4
"personalAccessToken": "<your-personal-access-token>",
5
"rules": [
6
{
7
"name": "Get tokens from all collections whose names contain 'colors'",
8
"parsers": [
9
{
10
"name": "filter",
11
"options": {
12
"where": {
13
"collection": "colors",
14
"select": {
15
"collection": true,
16
"children": {
17
"tokens": true
18
}
19
}
20
}
21
}
22
}
23
]
24
}
25
]
26
}

Select tokens from a specific group

.specifyrc.json
1
{
2
"version": "2",
3
"repository": "@organization/repository",
4
"personalAccessToken": "<your-personal-access-token>",
5
"rules": [
6
{
7
"name": "Get tokens from all groups named 'brand'",
8
"parsers": [
9
{
10
"name": "filter",
11
"options": {
12
"query": {
13
"where": {
14
"group": "^brand$",
15
"select": {
16
"parents": true,
17
"children": true
18
}
19
}
20
}
21
}
22
}
23
]
24
}
25
]
26
}

Select tokens of a specific type from a collection

.specifyrc.json
1
{
2
"version": "2",
3
"repository": "@organization/repository",
4
"personalAccessToken": "<your-personal-access-token>",
5
"rules": [
6
{
7
"name": "Get color tokens from the 'Android' collection",
8
"parsers": [
9
{
10
"name": "filter",
11
"options": {
12
"query": {
13
"where": {
14
"collection": "^Android$",
15
"andWhere": {
16
"token": ".*",
17
"withTypes": { "include": ["color"] },
18
"select": {
19
"token": true,
20
"parents": {
21
"collections": true
22
}
23
}
24
}
25
}
26
}
27
}
28
}
29
]
30
}
31
]
32
}

Select all tokens from a collection and from groups matching a naming pattern

.specifyrc.json
1
{
2
"version": "2",
3
"repository": "@organization/repository",
4
"personalAccessToken": "<your-personal-access-token>",
5
"rules": [
6
{
7
"name": "Get color tokens from the 'Android' collection and from all groups named 'components'",
8
"parsers": [
9
{
10
"name": "filter",
11
"options": {
12
"query": {
13
"where": {
14
"collection": "^Android$",
15
"andWhere": {
16
"group": "^components$",
17
"andWhere": {
18
"token": ".*",
19
"withTypes": {
20
"include": ["color"]
21
},
22
"select": {
23
"token": true,
24
"parents": true
25
}
26
}
27
}
28
}
29
}
30
}
31
}
32
]
33
}
34
]
35
}

Select tokens from several groups with different names

.specifyrc.json
1
{
2
"version": "2",
3
"repository": "@organization/repository",
4
"personalAccessToken": "<your-personal-access-token>",
5
"rules": [
6
{
7
"name": "Get tokens from the group named 'Components' and/or from the group named 'Semantic'",
8
"parsers": [
9
{
10
"name": "filter",
11
"options": {
12
"query": {
13
"where": {
14
"collection": "^Android$",
15
"andWhere": {
16
"group": "^Components$|^Semantic$",
17
"andWhere": {
18
"token": ".*",
19
"select": {
20
"token": true,
21
"parents": true
22
}
23
}
24
}
25
}
26
}
27
}
28
}
29
]
30
}
31
]
32
}

Select design tokens from a specific type

{
"version": "2",
"head": "specifyrc-json",
"base": "main",
"repository": "@organization/repository",
"rules": [
{
"name": "css",
"parsers": [
{
"name": "filter",
"options": {
"query": {
"where": {
"token": ".*",
"withTypes": {
"include": [
"color"
]
},
"select": {
"parents": true
}
}
}
}
}
]
}
]
}