edgedb-js
edgedb-js copied to clipboard
Querybuilder generates invalid edgeql for invalid insert shape
From issue: https://github.com/edgedb/edgedb/issues/3647
If function returning a shape object is used instead of plain shape object in e.insert
:
e.insert(e.Person, () => ({
firstName: 'john',
lastName: 'smith'
}))
querybuilder generates the following incorrect edgeql:
INSERT default::Person {
id
}
Typescript does catch this mistake, but we should still check at runtime and throw specific error instead of generating incorrect edgeql.
I was also trying to insert a blank Person with the following query, not sure if this is related. But it is the same error.
await e.insert(e.Person, {}).run(client)
InternalServerError: invalid reference to FROM-clause entry for table "Person~1"
Typescript does catch this mistake, but we should still check at runtime and throw specific error instead of generating incorrect edgeql.
It does not seem to catch the error for me on Typescript, the following does not throw TS errors:
// This is valid, even though the shape doesn't even match.
const query = e.insert(e.User, () => ({
name: "Hello",
this_does_not_exist: "x",
}));
const result = await query.run(client); // <{ id: string; }>
Using edgedb-js 0.19.15, Typescript 4.6.2 and client is freshly generated using --target cjs
.
Am I missing an use case for inserts that return a shape from a function?
I was also trying to insert a blank Person with the following query, not sure if this is related. But it is the same error.
Yep, that should be valid, but the querybuilder also mistakenly injects an id
into the shape here as well.
This seems to be fixed in the latest version and has test coverage.