impress-2020/scripts/build-cached-data.js
Matchu e5081dab7e Disable honeycomb auto instrumentation
Huh, well, I can't figure out what in our production env stopped working with Honeycomb's automatic instrumentation… so, oh well! Let's try disabling it for now and see if it works.

This means our Honeycomb logs will no longer include _super helpful_ visualizations of how HTTP requests and MySQL queries create a request dependency waterfall… but I haven't opened Honeycomb in a while, and this bug is blocking all of prod, so if this fixes the site then I'm okay with that as a stopgap!

Btw the error message was:
```
Unhandled rejection: TypeError: Cannot read property 'id' of undefined    at exports.instrumentLoad (/var/task/node_modules/honeycomb-beeline/lib/instrumentation.js:80:14)    at Function._load (/var/task/node_modules/honeycomb-beeline/lib/instrumentation.js:164:16)    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)    at ModuleJob.run (internal/modules/esm/module_job.js:169:25)    at Loader.import (internal/modules/esm/loader.js:177:24)
```

Oh also, this is the first time eslint has looked at scripts/build-cached-data.js I guess, so I fixed some lint errors in there.
2021-08-08 00:14:55 -07:00

62 lines
1.6 KiB
JavaScript

// We run this on build to cache some stable database tables into the JS
// bundle!
require("honeycomb-beeline")({
writeKey: process.env["HONEYCOMB_WRITE_KEY"],
dataset:
process.env["NODE_ENV"] === "production"
? "Dress to Impress (2020)"
: "Dress to Impress (2020, dev)",
serviceName: "impress-2020-build-process",
enabledInstrumentations: [],
});
const fs = require("fs").promises;
const path = require("path");
const { ApolloServer } = require("apollo-server");
const { createTestClient } = require("apollo-server-testing");
const gql = require("graphql-tag");
const { config } = require("../src/server");
const cachedDataPath = path.join(__dirname, "..", "src", "app", "cached-data");
async function main() {
await fs.mkdir(cachedDataPath, { recursive: true });
// Check out this scrappy way of making a query against server code ^_^`
const { query } = createTestClient(new ApolloServer(config));
const res = await query({
query: gql`
query BuildCachedData {
allZones {
id
label
depth
isCommonlyUsedByItems
}
}
`,
});
if (res.errors) {
for (const error of res.errors) {
console.error(error);
}
throw new Error(`GraphQL request failed`);
}
const filePath = path.join(cachedDataPath, "zones.json");
await fs.writeFile(
filePath,
JSON.stringify(res.data.allZones, null, 4),
"utf8"
);
console.info(`📚 Wrote zones to ${path.relative(process.cwd(), filePath)}`);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.then(() => process.exit());