Grafserv imports Ruru which breaks bundling
- I am deploying to AWS lambda, which involves bundling
grafservimportsrurururudoes all kinds of bundler-incompatible things like trying toreadFileSyncpackage.jsonetc
The stack looks like
Error: ENOENT: no such file or directory, open '/var/package.json'
at Object.openSync (node:fs:603:3)
at readFileSync (node:fs:471:35)
at mapIterator (/node_modules/ruru/src/server.ts:7:3)
at file:///var/task/pglambda-v2.mjs:9:495
at getGrafservHooks (/node_modules/grafserv/src/middleware/graphiql.ts:2:1)
at file:///var/task/pglambda-v2.mjs:9:495
at optionsFromConfig (/node_modules/grafserv/src/core/base.ts:22:1)
at file:///var/task/pglambda-v2.mjs:9:495
at <anonymous> (/node_modules/grafserv/src/index.ts:1:1)
at file:///var/task/pglambda-v2.mjs:9:495
As a first pass, I suggest making ruru lazily evaluate non-bundleable code so that it can be imported in bundled contexts without error.
Also: https://github.com/graphile/crystal/blob/7d5a40fa581e307ef48b51b18185355f0d49f3de/grafast/ruru/src/server.ts#L9-L11 which seems to cause issues with Nuxt bundling.
We actually have a "version" script that we use to keep the versions in sync without requiring a read of package.json, so should be trivial to expand that to this package.json read; see:
https://github.com/graphile/crystal/blob/main/grafast/grafast/src/version.ts
Fixing the above read of ruru.min.js is going to be a different thing; but I think we can just use something like this to inline it into JS instead of reading from file:
https://github.com/graphile/worker/blob/aae7527fe4a2e3464bb2f198a228c4219ffc6cd9/scripts/buildSqlModule.js#L10-L22
Darn, just hit this one as well when deploying to Vercel which, uses AWS Lambda.