← Back to Home

Examples

Query patterns, response structures, and domain schemas demonstrating DGP usage

v0.8.0

{ } Example Queries

Common query patterns including simple lookups, relationship traversal, filtering, aggregations, and computed fields.

queries.json 3.1 KB 5 examples
{
  "name": "Customer with Orders and Line Items",
  "query": {
    "entity": "Customer",
    "where": {
      "email": { "eq": "jane.doe@example.com" }
    },
    "include": {
      "orders": {
        "where": { "status": { "in": ["confirmed", "shipped"] } },
        "limit": 10,
        "include": { "line_items": {} }
      }
    }
  }
}

{ } Example Responses

Response structures with execution metadata, cost breakdown, freshness indicators, and provenance information.

responses.json 13 KB 3 examples
{
  "data": [{ "id": "cust_12345", "email": "jane@example.com" }],
  "metadata": {
    "execution": {
      "query_id": "q_abc123",
      "duration_ms": 45,
      "rows_scanned": 1
    },
    "cost": {
      "tokens": 12,
      "breakdown": { "query_parse": 2, "execution": 8 }
    },
    "freshness": { "age_seconds": 0, "cached": false }
  }
}

E-Commerce Domain (CSN)

Complete domain schema in Compressed Schema Notation featuring Customer, Order, Product, Payment entities with relationships and state machines.

ecommerce.csn 5.5 KB 6 entities · 4 operations
# Domain Graph Protocol - Compressed Schema Notation
# Domain: commerce | Entities: 6 | Operations: 4

## ENTITIES

Customer "A person or organization that purchases products"
  id : uuid! @key
  email : email! @unique @indexed
  name : string!
  lifecycle_stage : enum(prospect|lead|customer|champion|churned)
        @fsm{prospect -> lead : engaged, lead -> customer : first_purchase}
  lifetime_value : decimal @computed(sum:orders.total) @freshness(1h)
  ->* orders : Order @inverse(customer)

Quick Reference

Common patterns used in DGP queries:

Filter by ID

"where": {"id": {"eq": "..."}}

Include Relationship

"include": {"orders": {"limit": 10}}

Multiple Conditions

"where": {"status": {"in": ["a", "b"]}}

Computed Fields

"computed": ["lifetime_value"]

Pagination

"limit": 20, "offset": 40

Sorting

"order_by": {"created_at": "desc"}