There are three ways to interact with your data in your Gadget apps:
API access: Read and write data, and run custom business logic.
Computed fields: Read-only fields on models that can transform data, and aggregate data across relationships.
Computed views: Read-only queries capable of running complex data computations and aggregations.
API access
Gadget automatically generates and documents GraphQL CRUD (create, read, update, delete) APIs for your application as you add, update, and delete models. You can extend this API by adding custom actions.
A Node.js API client is also generated and used to makes requests with JavaScript or TypeScript. React hooks built by the Gadget team can be used to read and write data from your frontend.
Use the API for most CRUD operations and any actions that require business logic.
Computed views are complex, read-only Gelly queries that allow you to perform aggregations, filtering, and transformations on a large dataset, across multiple models and/or relationships.
They are useful for creating reports, dashboards, or any other complex queries that need to aggregate and manipulate data across models.
Example of a computed view:
a computed view for top 10 products ordered by total sales
gelly
view topProducts {
products {
name
totalSales: sum(orders.totalPrice)
[order by totalSales desc limit 10]
}
}
Computed views are callable from your API and can be predefined or called inline using your API client.
Using api.view() for inline views allows for dynamic query construction.
calling computed views
JavaScript
// a predefined computed view, called using the API client
const result = await api.product.topProducts();
// an the same computed view with a dynamic limit, called inline with api.view()
const result2 = await api.view(`{
products {
name
totalSales: sum(orders.totalPrice)
[order by totalSales desc limit ${limit}]
}
`);
// a predefined computed view, called using the API client
const result = await api.product.topProducts();
// an the same computed view with a dynamic limit, called inline with api.view()
const result2 = await api.view(`{
products {
name
totalSales: sum(orders.totalPrice)
[order by totalSales desc limit ${limit}]
}
`);
Gelly is Gadget's data access language designed to handle complex computations and aggregations that are difficult to execute performantly with the public API. Similar to SQL, Gelly excels at computations across large volumes of data.
Gelly queries are declarative, enabling Gadget to precompute or re-compute values efficiently, which is why Gelly is used for both computed fields and computed views.