Describing your domain
Concepts, intents and relationships
Semantic types give meaning to single values, like a FirstName or an OrderId.
Models describe the data structures that real systems return.
Taxi has three more declarations for describing your domain at a higher level:
| Declaration | What it names | Example |
|---|---|---|
concept | A kind of thing, described by the values it has | A Person has a FirstName and a LastName |
intent | An action, described by what goes in and what comes out | Purchase takes a product request and returns a confirmation |
relationship | A named link from one kind of thing to another | A Person worksFor a LegalEntity |
A fourth keyword, satisfies, connects your models and operations to them.
A quick example
type PersonId inherits String
type FirstName inherits String
type LastName inherits String
type LegalEntityId inherits String
type LegalEntityName inherits String
type HireDate inherits Date
// The things in the domain
concept Person { PersonId, FirstName, LastName }
concept LegalEntity { LegalEntityId, LegalEntityName }
// How they connect
relationship worksFor: Person -> LegalEntity?
// An action
write intent Hire(Person, LegalEntityId, HireDate): PersonId
// One system's data, declared against the concepts
model HrEmployer satisfies LegalEntity {
id: LegalEntityId
name: LegalEntityName
}
model HrEmployee satisfies Person, worksFor {
id: PersonId
first: FirstName
last: LastName
employer: HrEmployer?
}
parameter model NewHire {
personId: PersonId
first: FirstName
last: LastName
employerId: LegalEntityId
startDate: HireDate
}
service HrApi {
operation employee(PersonId): HrEmployee
write operation hire(NewHire): PersonId satisfies Hire
}Here’s what each part does:
concept Personsays that a person has aPersonId, aFirstNameand aLastName. It doesn’t say how that data is laid out.model HrEmployee satisfies Personsays that the HR system’s employee record is aPerson. The compiler checks that it has the valuesPersonneeds.relationship worksFornames the link from a person to their employer.HrEmployeedeclares that it holds that link, in itsemployerfield.write intent Hirenames the action of hiring someone.HrApi::hiredeclares that it performs it, and the compiler checks that its inputs and output fit.
Why use them?
Models describe the shape of one system’s data. Different systems describe the same thing in different shapes. A person might be a nested JSON object in one API, and a flat CSV row in another.
Concepts, intents and relationships let you describe your domain once, then declare how each system fits it. The compiler checks each declaration, so mismatches are caught when you compile, not when you run a query.
In queries, you can then ask for things by what they mean. Using the schema above:
find { Person } as {
name: FirstName
employer: LegalEntityName? = worksFor::LegalEntityName
}This query doesn’t name a system, a model or a field path. The compiler works out where worksFor is held.
For readers who know OWL
If you've used OWL or other ontology languages: a concept is close to a class, and a relationship is close to an object property. Taxi's version is checked by the compiler against the models you already have, rather than being a separate description of them.
Everything is declared
A model only satisfies a concept, or holds a relationship, if it says so with satisfies.
An operation only performs an intent if it says so.
The compiler doesn’t infer these by looking at structure. A model with exactly the fields a concept needs, but no satisfies, isn’t treated as that concept.
Inferring matches from structure may come in a later release, for concepts and relationships.
Concepts can't be created
A concept has no fields and no data of its own. You can’t use one as a field type, an operation parameter or return type, or a given value.
Anything that “returns a person” returns a model that satisfies Person.
The compiler reports CONCEPT_NOT_CONSTRUCTIBLE when a concept is used where a value would be created. See Concepts for the full list.
Queries
TaxiQL has three new query forms:
| Query | What it does | Read more |
|---|---|---|
find { Person } | Finds data from a model that satisfies Person | Concepts |
call Hire | Calls the operation that performs the Hire intent | Intents |
worksFor::LegalEntityName | Follows a relationship inside a projection | Relationships |
Query execution is coming
The Taxi compiler supports these query forms today: they compile, and they're type-checked against your schema. Support for running them is still being built in the query engine.
Next steps
- Concepts: declaring concepts, and models that satisfy them
- Intents: declaring actions, and operations that perform them
- Relationships: declaring links between concepts, and following them in queries