Configuration Guide

Guide to configuring and using TypeMUX.

Table of Contents

CLI Flags

TypeMUX accepts the following command-line flags:

-input

Required. Path to the input TypeMUX schema file.

typemux -input schema.typemux

Multiple files: Use imports in your schema file instead of multiple -input flags.

-format

Output format to generate. Default: all

Options:

Examples:

# Generate all formats
typemux -input schema.typemux -format all

# Generate only GraphQL
typemux -input schema.typemux -format graphql

# Generate only Go code
typemux -input schema.typemux -format go

# Generate only documentation
typemux -input schema.typemux -format markdown

-output

Output directory for generated files. Default: ./generated

typemux -input schema.typemux -output ./gen
typemux -input schema.typemux -output /tmp/api-schemas

Created files:

-annotations

Path to YAML annotations file. Can be specified multiple times.

# Single annotations file
typemux -input schema.typemux -annotations annotations.yaml

# Multiple files (merged, later files override earlier)
typemux -input schema.typemux \
        -annotations base-annotations.yaml \
        -annotations environment-specific.yaml

-config

Path to configuration file. See Config File section.

typemux -config typemux.config.yaml

Complete Example

typemux \
  -input api/schema.typemux \
  -format all \
  -output ./generated/api \
  -annotations api/annotations.yaml

Config File

Instead of CLI flags, you can use a YAML configuration file:

File Format

# typemux.config.yaml
input: schema.typemux
output:
  directory: ./generated
  formats:
    - graphql
    - protobuf
    - openapi
    - go
annotations:
  - base-annotations.yaml
  - overrides.yaml

Configuration Options

Option Type Description Default
input string Path to schema file Required
output.directory string Output directory ./generated
output.formats array Formats to generate ["all"]
annotations array YAML annotation files []

Usage

# Use config file
typemux -config typemux.config.yaml

# Override with CLI flags
typemux -config typemux.config.yaml -format graphql -output ./custom

Priority: CLI flags override config file settings.

YAML Annotations

YAML annotation files provide format-specific metadata without cluttering schema files.

Note: For annotation syntax and available annotations, see the Language Reference.

File Structure

types:
  TypeName:
    proto:
      - option_name = "value"
    graphql:
      - '@directive'
    openapi:
      - x-extension: value
    go:
      - package = "pkgname"

    fields:
      fieldName:
        proto:
          - option = "value"
        graphql:
          - '@directive(arg: "value")'
        openapi:
          - x-field-extension: value

enums:
  EnumName:
    proto:
      - allow_alias = true

    values:
      VALUE_NAME:
        proto:
          - option = "value"

services:
  ServiceName:
    proto:
      - option = "value"

    methods:
      MethodName:
        proto:
          - option = "value"
        openapi:
          - x-method-extension: value

Complete Example

annotations.yaml:

types:
  User:
    proto:
      - deprecated = true
    graphql:
      - '@key(fields: "id")'
    openapi:
      - x-internal: true

    fields:
      email:
        proto:
          - json_name = "emailAddress"
        graphql:
          - '@deprecated(reason: "Use emailAddress")'

      password_hash:
        proto:
          - json_name = "password"

enums:
  UserRole:
    proto:
      - allow_alias = true

    values:
      ADMIN:
        proto:
          - option = "(custom.role_level) = 100"

services:
  UserService:
    proto:
      - deprecated = false

    methods:
      GetUser:
        openapi:
          - x-rate-limit: 1000

Qualified Names (with Namespaces)

When using namespaces, reference types by their qualified names:

types:
  # Fully qualified name
  com.example.users.User:
    proto:
      - option = "value"

  # Another namespace
  com.example.orders.Order:
    fields:
      userId:
        proto:
          - json_name = "user_id"

Format-Specific Options

Protobuf Options

Standard Protobuf options:

Custom options:

proto:
  - (my.custom.option) = "value"
  - (validate.rules).string.email = true

GraphQL Directives

graphql:
  - '@key(fields: "id")'
  - '@external'
  - '@requires(fields: "userId")'
  - '@deprecated(reason: "Use newField")'

OpenAPI Extensions

Any property starting with x-:

openapi:
  - x-internal: true
  - x-rate-limit: 1000
  - x-nullable: true
  - x-format: email

Go Options

go:
  - package = "mypackage"
  - json = "omitempty"

Validation and Deprecation

See Language Reference - Validation for details on validation annotations.

Annotation Merging

When annotations are specified in multiple places, TypeMUX merges them with a specific priority.

Merge Order (highest to lowest priority)

  1. YAML annotations (last file wins if multiple files)
  2. Inline annotations in schema file

Example:

schema.typemux:

type User {
  email: string @required
}

annotations.yaml:

types:
  User:
    fields:
      email:
        proto:
          - json_name = "emailAddress"

Result: Field email has both @required (from inline) and json_name (from YAML).

Multiple YAML Files

When using multiple YAML annotation files:

typemux -input schema.typemux \
        -annotations base.yaml \
        -annotations override.yaml

Merge behavior:

Example:

base.yaml:

types:
  User:
    proto:
      - deprecated = false
    fields:
      email:
        proto:
          - json_name = "email"

override.yaml:

types:
  User:
    proto:
      - deprecated = true
    fields:
      email:
        graphql:
          - '@deprecated(reason: "Old field")'

Result:

Use Cases

Environment-specific configuration:

typemux -input schema.typemux \
        -annotations base-annotations.yaml \
        -annotations prod-overrides.yaml

Team-specific overrides:

typemux -input schema.typemux \
        -annotations shared-annotations.yaml \
        -annotations team-customizations.yaml

Best Practices

When to Use Inline vs YAML Annotations

Use inline annotations when:

Use YAML annotations when:

Example split:

schema.typemux (business logic):

type User {
  id: string @required
  email: string @required
  age: int32
}

annotations.yaml (format-specific):

types:
  User:
    proto:
      - deprecated = false
    graphql:
      - '@key(fields: "id")'
    fields:
      email:
        proto:
          - json_name = "emailAddress"

Annotation Organization

Small projects:

schema.typemux
annotations.yaml

Medium projects:

schema.typemux
annotations/
  protobuf.yaml
  graphql.yaml
  openapi.yaml

Large projects:

schemas/
  users.typemux
  orders.typemux
annotations/
  base/
    users.yaml
    orders.yaml
  environments/
    prod.yaml
    staging.yaml
  teams/
    backend.yaml
    mobile.yaml

Configuration File Usage

Simple project:

# typemux.config.yaml
input: schema.typemux
output:
  formats: [graphql, protobuf]

Complex project:

# typemux.config.yaml
input: schemas/main.typemux
output:
  directory: generated
  formats:
    - graphql
    - protobuf
    - openapi
    - go
annotations:
  - annotations/base.yaml
  - annotations/prod.yaml

Version Control

Always commit:

Add to .gitignore:

generated/
*.proto
*.graphql
openapi.yaml
types.go
schema.md

Troubleshooting

Common Issues

Error: “file not found”

Error: “unknown annotation”

Generated files are empty

Annotations not applied

Import errors

Getting Help

If you encounter issues:

  1. Check the Language Reference for syntax
  2. Review examples for similar use cases
  3. Enable verbose output to see what TypeMUX is doing
  4. File an issue on GitHub

See Also