edgedb / edgedb-js

The official TypeScript/JS client library and query builder for EdgeDB
https://edgedb.com
Apache License 2.0
514 stars 65 forks source link

Webpack issue with `.edgeql.ts` file generation #639

Closed jackfischer closed 1 year ago

jackfischer commented 1 year ago

Describe the bug

Follow up from Discord: When using TS Queries Generator with next.js webpack doesn't know how to process the .edgeql.ts files. @1st1 said it should generate _edgeql.ts files instead.

Reproduction Run @edgedb/generate queries, import the resulting TS files in next.js.

./queries/Xyz.edgeql
Module parse failed: Unexpected token (3:11)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

Versions (please complete the following information): @edgedb/generate 0.1.1

scotttrinh commented 1 year ago

We actually recently merged a change that makes it .query.ts but have t cut a new release yet. Will do ASAP. In the meantime the --file option does work.

jackfischer commented 1 year ago

.query.ts would suffer the same problem no? It seemed like issue is webpack not recognizing the extension

scotttrinh commented 1 year ago

The problem is that since there is a file named foo.edgeql and we were generating a foo.edgeql.ts, when you made an import, webpack (and typescript itself, actually) would try to import the EdgeQL file foo.edgeql instead of the generated TypeScript file. Renaming the generated file to foo.query.ts means that importing "foo.query" will properly see the foo.query.ts file, unless you also have a file named foo.query.

See https://github.com/edgedb/edgedb-js/issues/540 for more discussion here.

Fixed in the new release that just went out!

jackfischer commented 1 year ago

That makes much more sense, thanks.