nodejs-store

AI data-QA agent

The problem

You want users to ask questions in natural language — “which products have more than three orders?” — and get real rows back. An LLM can translate the question into a query, but you cannot run whatever the model produced blindly: a query that cannot be pushed down to the target backend, or that fans out across sources, must be caught before execution, and every degraded path must be visible instead of silently returning wrong or partial data.

You also need the generated query to be inspectable, so you can show it to the user or assert its shape in tests.

Why nodejs-store

The natural-language → GQL translation itself is out of scope for this library — it is what the companion text-to-query skill produces. nodejs-store is the layer that compiles, plans and executes that GQL.

Walkthrough

const { store, PushdownUnsupportedError } = require('nodejs-store');

// 1. Route every fallback / degradation / interception event into your own logger.
//    Pass null to restore the default stderr printer.
store.setFeedbackSink((e) => logger.warn({ code: e.code, layer: e.layer }, e.hint));
// event shape: { type, code, layer, message, hint, ... }
//   type   federation_degraded | sql_pushdown_unsupported | ...
//   code   crossSourceSort | pushdownUnsupported | ...
//   layer  federation | dialect | ...

// 2. The natural-language layer (see the text-to-query skill) turns the question
//    into a GQL string plus its params.
const gql = 'Product($condition:@c0,$sort:@s0){ _id, name }';
const params = { c0: { status: 'onSale', orders: { $count: { $gt: 3 } } }, s0: { name: 1 } };

// 3. Compile & validate the plan WITHOUT executing it.
const plan = store.buildPipeline(gql, params);
// plan = { tokens, ast, pipeline, projection }
if (!plan.pipeline || plan.pipeline.length === 0) {
  throw new Error('the generated query did not compile to a command');
}

// 4. Execute the same GQL through the normal path, where permissions and
//    computed columns are applied and pushdown failures are explicit.
try {
  const rows = await store.query(gql, params, { source: 'pg_a' });
  return { gql, rows };
} catch (err) {
  if (err instanceof PushdownUnsupportedError) {
    // A sql_pushdown_unsupported feedback event was already emitted above.
    return { gql, rows: [], reason: 'query cannot be pushed down to this backend' };
  }
  throw err;
}

Pitfalls

See also