Embedded Resources

View Source

AshTypescript provides full support for embedded resources with complete type safety. Embedded resources are treated similarly to relationships, allowing you to select nested fields with the same field selection syntax.

Basic Usage

Define an embedded resource attribute in your Ash resource:

# In your resource
attribute :metadata, MyApp.TodoMetadata do
  public? true
end

Use field selection to request embedded resource fields:

// TypeScript usage
const todo = await getTodo({
  fields: [
    "id", "title",
    { metadata: ["category", "priorityScore", "tags", "customFields"] }
  ],
  input: { id: "todo-123" }
});

Type Safety

Embedded resources receive full type inference:

// Generated types include embedded resource fields
type Todo = {
  id: string;
  title: string;
  metadata?: {
    category: string;
    priorityScore: number;
    tags: string[];
    customFields: Record<string, any>;
  } | null;
};

See Also