Repository navigation
Description
Overview
Implement QueryEditor component as a simple JSON textarea for editing query definitions. This MVP approach allows manual query creation/editing while laying groundwork for future visual builder or natural language interface.
Architecture References
- Component Architecture Guide:
docs/architecture/components/component-architecture-guide.md - Query Types: Defined in QueryNode Behavior and Core Type Definitions #439
Problem Statement
Users need a way to create and edit QueryDefinition JSON manually. While a visual query builder or natural language interface would be ideal, we need a working solution now that can be progressively enhanced later.
Dependencies
- QueryNode Behavior and Core Type Definitions #439: QueryNode types (QueryDefinition)
- QueryService with SQL Query Execution #440: QueryService (for preview functionality)
Proposed Solution
Progressive Enhancement Path
Phase 1 (This Issue): JSON textarea with validation
Phase 2 (Future): Visual query builder with filter chips
Phase 3 (Future): Natural language interface (AI converts text to QueryDefinition)
All modes operate on the same QueryDefinition type, making upgrades non-breaking.
Why JSON First?
- Immediate functionality (no complex UI needed)
- Full query power (no limitations from simplified UI)
- Developer-friendly for power users
- Easy to copy/paste/share queries
- Foundation for future enhancements
Implementation
File: packages/desktop-app/src/lib/components/query/query-editor.svelte
<script lang="ts">
import { queryService } from '$lib/services/query-service';
import type { QueryDefinition } from '$lib/types/query';
let {
query = null,
onSave,
onCancel
}: {
query?: QueryDefinition | null;
onSave: (query: QueryDefinition) => void;
onCancel?: () => void;
} = $props();
const DEFAULT_QUERY: QueryDefinition = {
targetType: 'task',
filters: [],
limit: 50
};
let queryJson = $state(JSON.stringify(query || DEFAULT_QUERY, null, 2));
let error = $state<string | null>(null);
let previewCount = $state<number | null>(null);
function validateAndSave() {
try {
const parsed = JSON.parse(queryJson) as QueryDefinition;
// Basic validation
if (!parsed.targetType) {
throw new Error('Missing required field: targetType');
}
if (!Array.isArray(parsed.filters)) {
throw new Error('filters must be an array');
}
error = null;
onSave(parsed);
} catch (e) {
error = e instanceof Error ? e.message : 'Invalid JSON';
}
}
async function loadPreview() {
try {
const parsed = JSON.parse(queryJson) as QueryDefinition;
const results = await queryService.execute(parsed);
previewCount = results.length;
} catch {
previewCount = null;
}
}
</script>
<div class="query-editor">
<div class="editor-header">
<h2>Query Definition</h2>
<button onclick={loadPreview} class="preview-btn">
Preview ({previewCount !== null ? `${previewCount} results` : 'click to preview'})
</button>
</div>
<textarea
bind:value={queryJson}
rows="20"
class="query-textarea font-mono"
placeholder="Enter QueryDefinition JSON..."
/>
{#if error}
<div class="error-message">{error}</div>
{/if}
<details class="examples">
<summary>Query Examples & Templates</summary>
<!-- Include example queries -->
</details>
<div class="editor-footer">
<button onclick={validateAndSave} class="save-btn">Save Query</button>
{#if onCancel}
<button onclick={onCancel} class="cancel-btn">Cancel</button>
{/if}
</div>
</div>Query Examples to Include
All Incomplete Tasks
{
"targetType": "task",
"filters": [
{ "type": "property", "operator": "in", "property": "status", "value": ["open", "in_progress"] }
]
}Recent Text Nodes with Keyword
{
"targetType": "text",
"filters": [
{ "type": "content", "operator": "contains", "value": "meeting" }
],
"sorting": [{ "field": "created_at", "direction": "desc" }],
"limit": 10
}Children of Specific Node
{
"targetType": "*",
"filters": [
{ "type": "relationship", "relationshipType": "children", "nodeId": "your-node-id" }
]
}Acceptance Criteria
- QueryEditor renders with JSON textarea
- Invalid JSON shows clear error message
- Valid QueryDefinition can be saved
- Cancel action discards changes
- Query templates/examples provided
- Preview shows estimated result count
- Component works in both create and edit modes
- Tests pass (
bun run test:all) - Code passes
bun run quality:fix
Testing Requirements
- Unit tests for JSON validation logic
- Integration tests for save/cancel flows
- Tests for query examples (all examples are valid)
- Keyboard accessibility tests
Non-Goals
- Visual query builder (future enhancement)
- Natural language interface (future enhancement)
- Syntax highlighting with Monaco editor (optional nice-to-have)
Activity
feat: complete query system — property filters, editor, and preferenc…
fix: address all 10 code review findings from PR #1044
Add property filter support to query_nodes MCP handler (#1044)
malibio commentedon Apr 5, 2026
Implemented in PR #1044 — QueryEditor component with JSON textarea, validation, preview, and template examples.
Add property filter support to query_nodes MCP handler (#1044)