edgedb-js
edgedb-js copied to clipboard
Incorrect syntax generated for property off of select that actually queries correctly
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-jsversion (e.g.0.20.10;): 1.5.6@edgedb/generateversion (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 https://github.com/edgedb/edgedb-js/blob/a44f17419768756688c5e7590df3405cebb2cf50/packages/generate/src/syntax/query.ts#L21-L24)
Maybe we should expose another method like .toRunnableEdgeQL that will do the same thing 🤔