edgedb/edgedb-js

Incorrect syntax generated for property off of select that actually queries correctly

jackfischer opened this issue · 1 comments

Code

const selectQuery = e.select(e.ActivitySnapshot, () => ({
  id: true,
})).id;
console.log(selectQuery.toEdgeQL()); // see below
console.log(await selectQuery.run(Client)); // [], no exception thrown

Schema

# as applicable to this example
module default {
  type ActivitySnapshot {}
}

Generated EdgeQL

(WITH
  __scope_0_defaultActivitySnapshot := DETACHED default::ActivitySnapshot
SELECT __scope_0_defaultActivitySnapshot {
  id
}).id

Error or desired behavior

The generated EdgeQL throws EdgeQLSyntaxError when executed directly Unexpected '('. It does not throw an error on selectQuery.run and in fact returns "correct" results.

Versions (please complete the following information):

  • OS: macos 14.5
  • EdgeDB version (e.g. 2.0): 4.7
  • EdgeDB CLI version (e.g. 2.0): 5.1.0
  • edgedb-js version (e.g. 0.20.10;): 1.5.6
  • @edgedb/generate version (e.g. 0.0.7;): 0.5.3
  • TypeScript version: 5.4.5
  • Node/Deno version: 20.11.1

I think the real issue here is that run knows how to wrap these fragments in a way that sends a valid query. (See

const expr = runnableExpressionKinds.has(this.__kind__)
? this
: wrappedExprCache.get(this) ??
wrappedExprCache.set(this, select(this)).get(this);
)

Maybe we should expose another method like .toRunnableEdgeQL that will do the same thing 🤔