Define Resolvers in the Onyx Cloud Admin Console
Resolvers let you attach reusable data fetchers and computed relationships to your schema. Use the Admin Console’s dedicated editor to wire complex joins, cascade queries, or enrichment logic without leaving the browser—and tap into the AI Schema Assistant to generate production-ready resolver code instantly.
Overview
A resolver transforms or enriches a record every time it is retrieved. Each resolver is linked to a named attribute and returns data fetched through the Onyx Database JavaScript SDK. You can configure them alongside attributes, indexes, and triggers inside the schema form.
- Reusable logic: Define a resolver once and call it from queries or the API.
- Type-safe execution: Access the fluent query builder (
db.from()
,where()
,eq()
, etc.) directly inside the editor. - AI acceleration: Generate or refine resolver implementations with natural language instructions.
Access the Resolver Editor
The resolver experience is integrated into the Schema Form Editor so you can edit table metadata and logic in one view.
Open your database schema
Sign in to the Onyx Cloud Admin app, choose your organization and database, then select the Schema tab.
Expand a table
In the Form Editor, click the table name you want to modify. The detail panel reveals sections for identifiers, attributes, resolvers, indexes, and triggers.
Locate "Attributes with Resolvers"
Scroll to the Attributes with Resolvers section. This grid lists every resolver currently attached to the table and provides controls for adding more.
Add a New Resolver
Create resolver stubs in seconds using the inline controls.
Click Add Resolver Attribute
The editor inserts a blank resolver row with inputs for the resolver name and Monaco-powered code editor.
Name the resolver
Use a property-style name (for example, eventDetails
or activeOrders
). The platform enforces lowerCamelCase naming so resolvers serialize cleanly.
Provide the implementation
Write TypeScript or JavaScript that returns a value with return await …
. The editor automatically persists code changes and supports resizing for longer scripts.
Write and Manage Resolver Logic
Resolvers execute server-side with a fully authenticated database client. They can reference the current record via this
and call the fluent query builder to gather related data.
Sample resolver
const relatedAds = await db .from("Ad") .where(eq("campaignId", this.id)) .and(eq("status", "Active")) .list(); return relatedAds;
The Onyx runtime injects db
, so you do not need to import the SDK manually. Compose queries with where()
and chain helpers like and()
or or()
when you need compound filters, then call list()
or firstOrNull()
to resolve the result.
Delete a resolver by clicking Remove in its row. This immediately updates the working schema, allowing you to manage multiple resolvers before publishing a batch of changes.
Accelerate with AI Assistance
The AI Schema Assistant can generate complete resolver definitions for you. Include resolver requirements in your prompt (for example, “add an eventDetails
resolver that fetches the related Event record”). The diff dialog will display the resolver name and code so you can apply it instantly.
Why use AI?
- Generate boilerplate that follows Onyx naming conventions.
- Produce multi-step lookups with validated SDK usage.
- Receive HTML summaries that spotlight every resolver the AI created or updated.
Refine with manual edits
After applying AI-generated changes, use the resolver editor to tweak field names, adjust filters, or add additional error handling before you publish.
Validate, Test, and Publish
- Validate the schema to catch syntax errors—this runs server-side checks on resolver JSON payloads.
- Publish to deploy resolvers to your database environment. The system tracks status so you can monitor progress in real time.
- Test in the Query Editor by selecting the resolver-enabled attribute or using the AI Query Assistant to confirm expected results.
Governance and Best Practices
- Use descriptive names: Resolver names appear in API payloads. Choose names that communicate intent to consumers.
- Return awaited values: Always
return await
the final query to ensure the resolver resolves to data rather than a promise. - Scope queries: Filter by
this.id
or other contextual fields to avoid unnecessary full-table scans. - Keep logic deterministic: Avoid non-idempotent operations (writes, randomization) inside resolvers to maintain predictable results.
- Document AI output: Add inline comments or commit notes describing AI-generated logic so teams can review and extend it confidently.
Troubleshooting
Resolver fails validation
Ensure the resolver body contains valid JSON-escaped strings if you are editing via JSON mode. Use the form editor to correct syntax and re-run validation.
Resolver returns no data
Confirm that your filters use this.property
values from the parent record. Test the same filters in the Query Editor to verify expected results.
Need to revert a resolver
Remove the resolver row in the form editor and publish. For AI-generated changes, open the diff dialog, remove the resolver operation, and regenerate with updated instructions.
Large resolver scripts
Use the editor’s resize handle to expand the Monaco editor or switch to the JSON editor for full-screen updates before returning to the form view.
Next Steps
Need Help?
If you have any questions or need assistance:
- Email:support@onyx.dev
- Documentation: Visit ourHelp Centerfor tutorials and FAQs.