Features
TypeScript ORM
The data sources that you add to your WunderGraph application can be accessed via our purpose-built TypeScript ORM (object-relational mapper).
Setup
Our ORM is currently alpha so expect bugs and API changes. Please report bugs and feature requests on GitHub 🙏
Since the ORM is experimental you must explicitly opt-in to said functionality. Set experimental.orm
to true
in your wundergraph.config.ts
.
Operations
The ORM supports read, write, and subscribe operations on the data sources configured in your WunderGraph application.
Reads
Read operations are specified via. the query
method. For example,
Writes
Write operations are specified via. the mutate
method. For example,
Subscriptions
Stream operations are specified via. the subscribe
method. For example,
Nested and Filtered Selections
As a convenience the ORM will select all scalar fields on an object type. In-order-to retrieve relations (or other arbitrarily nested fields on the object) and/or filter unwanted fields, one can provide a list of property paths to the select
method. For example,
Conditional Types
An important feature of the ORM is the support for interacting with types that are variable at runtime. As our virtual graph utilizes GraphQL to define it's semantics, the ORM encodes this behavior similarly.
Union Types
A union defines a set of possible types that the returned object may represent. The ORM currently requires specifying the fields you would like returned for each possible type. Select type-specific fields using the on(fields: ...Array<string>)
method, for example:
Interface Types
An interface defines a common set of properties that multiple objects can adhere to. For example, a Query.node(id: ID!)
API (under the foo
namespace) could be accessed like so:
Note: The ORM does not currently auto-select interface fields (i.e each field must be selected on each type). This will be improved soon!