Skip to Content
API ReferenceDesign Tokens

Design Tokens API

The designTokens query returns your project’s design tokens — both the raw W3C Design Tokens Format Module  document and a flat, server-resolved view. Use the resolved arrays at runtime; use source for build-time tooling like Style Dictionary.

For the feature overview, see Design Tokens. For the config shape, see Defining Design Tokens.

Tokens are a whole-project asset rather than a record, so the data client addresses them as a namespace operation — foir.ns.project.designTokens() — with no pick, no omit and nothing to paginate. Every GraphQL selection below is one call there, because the operation is complete by default.

Query

query DesignTokens { designTokens { source colors { path name description value } fontFamilies { path name description value } fontWeights { path name description value } fontSizes { path name description value } lineHeights { path name description value } letterSpacings { path name description value } typography { path name description label tag value { fontFamily fontSize fontWeight lineHeight letterSpacing textTransform } } spacings { path name description value } radii { path name description value } shadows { path name description layers { offsetX offsetY blur spread color inset } } borders { path name description value { color width style } } } }

The same read on the data client, which prints that whole selection for you:

const tokens = await foir.ns.project.designTokens();

No arguments either way. The query is scoped to the project of the API key making the request.

Channels

By default the query reads the published snapshot — the storefront-safe one. To preview unpublished edits, send the X-Foir-Schema-Channel: draft header on a request authenticated with a key that holds the drafts:read scope.

POST /graphql HTTP/1.1 Host: api.foir.dev Content-Type: application/json x-api-key: foir_adm_... X-Foir-Schema-Channel: draft

A publishable or a server key without drafts:read ignores the channel header and reads published — the safer default for storefront builds.

Field reference

DesignTokens

FieldTypeDescription
sourceJSONThe raw W3C document with {path.to.token} references intact. For build tooling.
colors[DesignTokenColor!]!Resolved color tokens.
fontFamilies[DesignTokenFontFamily!]!Resolved font-family tokens (each value is a string array — primary + fallbacks).
fontWeights[DesignTokenFontWeight!]!Resolved numeric font weights (100–900).
fontSizes[DesignTokenDimension!]!Resolved font sizes (CSS length strings).
lineHeights[DesignTokenNumber!]!Resolved unitless line-height multipliers.
letterSpacings[DesignTokenDimension!]!Resolved letter-spacing values.
typography[DesignTokenTypography!]!Composite tokens: fontFamily + fontSize + fontWeight + lineHeight + letterSpacing + optional textTransform.
spacings[DesignTokenDimension!]!Resolved spacing scale (spacing.*).
radii[DesignTokenDimension!]!Resolved corner-radius scale (radius.*).
shadows[DesignTokenShadow!]!Multi-layer drop shadows.
borders[DesignTokenBorder!]!Stamped borders — width + style + color.

Every resolved array is sorted by path for stable output.

Common fields

Every token type carries:

FieldTypeDescription
pathString!Dotted path identifying the token (e.g. color.brand.primary).
nameString!The leaf segment of path (e.g. primary).
descriptionStringThe $description from the W3C document.

Type-specific values

Typevalue shape
DesignTokenColorString! — CSS color string (hex, rgb(), etc.).
DesignTokenFontFamily[String!]! — primary + fallback stack.
DesignTokenFontWeightInt! — 100–900.
DesignTokenDimensionString! — any CSS length: 16px, 1rem, clamp(...).
DesignTokenNumberFloat! — unitless.
DesignTokenTypographyDesignTokenTypographyValue! — see below. Also exposes label and tag for editor metadata.
DesignTokenShadow[DesignTokenShadowLayer!]! via layers — one entry per layer.
DesignTokenBorderDesignTokenBorderValue! — { color, width, style }.

DesignTokenTypographyValue

FieldTypeDescription
fontFamily[String!]!Resolved font-family stack.
fontSizeString!Resolved CSS length.
fontWeightInt!Resolved 100–900 weight.
lineHeightFloat!Resolved unitless line height.
letterSpacingString!Resolved CSS length.
textTransformStringOptional — uppercase, lowercase, capitalize.

DesignTokenShadowLayer

FieldType
offsetX, offsetY, blur, spread, colorString!
insetBoolean!

Examples

Resolved colors → CSS variables

query Colors { designTokens { colors { path value } } }
const tokens = (await foir.ns.project.designTokens()) as { colors: Array<{ path: string; value: string }>; }; const css = tokens.colors .map((c) => `--${c.path.replaceAll('.', '-')}: ${c.value};`) .join('\n'); // --color-brand-black: #201917; // --color-brand-coral: #d4553a;

Typography → ready-to-render styles

query Typography { designTokens { typography { path label tag value { fontFamily fontSize fontWeight lineHeight letterSpacing textTransform } } } }
const { typography } = (await foir.ns.project.designTokens()) as { typography: Array<{ path: string; tag: string; value: { fontSize: string } }>; };

The composite value is fully resolved — no need to look up the referenced primitives separately.

Raw document for Style Dictionary

query Source { designTokens { source } }
const { source } = (await foir.ns.project.designTokens()) as { source: unknown };

source returns the W3C document with {path.to.token} references intact. Feed it to your build pipeline of choice. Note that the data client always returns the whole token set — source arrives alongside the resolved arrays rather than instead of them.

Previewing a draft

curl https://api.foir.dev/graphql \ -H "Content-Type: application/json" \ -H "x-api-key: foir_adm_..." \ -H "X-Foir-Schema-Channel: draft" \ -d '{"query":"{ designTokens { spacings { path value } } }"}'

Use this in preview environments to render the next-version look before clicking Publish.

Errors

StatusMessageCause
401API key or a signed-in person's token requiredThe request carries neither an x-api-key nor an Authorization token that verifies.
401Invalid or expired API keyThe x-api-key is not a live key.
403X-Foir-Schema-Channel: draft requires drafts:readYou sent X-Foir-Schema-Channel: draft with a key that doesn’t have the drafts:read scope.

Validation errors (cycles, unknown references, bad $type) surface at write time — foir push and the console editor reject them before they reach the read API. The designTokens query itself returns the stored document or an empty document for projects that haven’t authored tokens yet.

Last updated on