edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

Add predictability to order of files processed by `@edgedb/generate queries`

Open fredt34 opened this issue 1 year ago • 2 comments

In addition to #617 , about generate queries: I wrote a simple generator that introspects the schema and creates standard CRUD queries such as queries/system/getUserByID.edgeql, queries/system/getUserByAlias.edgeql, queries/system/get_all_User.edgeql ... where get_all_User.edgeql typically contains select User { * } ;

For some objects, I manually define a query with the the same name, in another 'manual' directory : queries/manual/get_all_User.edgeql - defining a "long version", select User { **, events: { ** } } ;

@edgedb/generate queries --file dbschema/queries then nicely generates 2 get_all_User functions (from system and manual)in queries.ts.

When I import get_all_User in my code, the second declaration "wins" and is executed.

Unfortunately running @edgedb/generate queries --file dbschema/queries multiple times shows that the file order differs between 2 executions - so I'm at risk of having the "system" version generated after the "long" one in the file. Tinkering with directory names, dir dates... didn't help into having a predictable list.

Adding a sort operation (by code or parameter) after calling getMatches would probably address this issue... as well as making the resulting queries.ts file easier to read (it's quite unsorted).

Running EdgeDB CLI 4.0.2+be1da73 with bun 1.0.18 on Ubuntu 22.04.3 LTS

fredt34 avatar Jan 26 '24 17:01 fredt34

@fredt34

Great idea, and thanks for the extra sleuthing there. PRs welcome!

scotttrinh avatar Jan 26 '24 17:01 scotttrinh

Another cause of nondeterminism here is that we run the query generation in parallel (see https://github.com/edgedb/edgedb-js/blob/316a398f9dbb413a880440086df7b5bebc7e68b5/packages/generate/src/queries.ts#L57) so to get truly deterministic ordering we'd need to do it in series.

scotttrinh avatar Jan 26 '24 17:01 scotttrinh