diff --git a/bun.lockb b/bun.lockb index f2cbd8b..2f1fc70 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/lib/logger/index.ts b/lib/logger/index.ts new file mode 100644 index 0000000..704b895 --- /dev/null +++ b/lib/logger/index.ts @@ -0,0 +1,19 @@ +import { type YogaLogger } from "graphql-yoga"; +import pino from "pino"; + +export const logger = pino(); + +export const yogaLogger: YogaLogger = { + debug(...args) { + logger.debug("", ...args); + }, + info(...args) { + logger.info("", ...args); + }, + warn(...args) { + logger.warn("", ...args); + }, + error(...args) { + logger.error("", ...args); + }, +}; diff --git a/package.json b/package.json index b18e0be..998ceef 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,10 @@ "module": "src/index.ts", "type": "module", "scripts": { - "dev": "bun src/index.ts --watch" + "dev": "bun --watch src/index.ts | pino-pretty" }, "devDependencies": { - "@types/bun": "latest", - "@types/pino": "^7.0.5" + "@types/bun": "latest" }, "peerDependencies": { "typescript": "^5.0.0" diff --git a/src/index.ts b/src/index.ts index 8a0f745..897da9b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,15 @@ -import { createYoga } from "graphql-yoga"; -import { schema } from "./schema"; +import { logger } from "@lib/logger"; +import { yoga } from "./yoga"; -const yoga = createYoga({ schema }); +const server = Bun.serve({ + fetch: yoga.fetch, + error: (error) => { + logger.error(error.message); + return new Response("", { + status: 500, + statusText: "You fucked the goose", + }); + }, +}); -const server = Bun.serve({ fetch: yoga.fetch }); - -console.log(`Server is running on: ${server.url}${yoga.graphqlEndpoint}`); +logger.info(`Server is running on: ${server.url}${yoga.graphqlEndpoint}`); diff --git a/src/yoga/index.ts b/src/yoga/index.ts new file mode 100644 index 0000000..43ce842 --- /dev/null +++ b/src/yoga/index.ts @@ -0,0 +1,8 @@ +import { yogaLogger } from "@lib/logger"; +import { createYoga } from "graphql-yoga"; +import { schema } from "./schema"; + +export const yoga = createYoga({ + schema, + logging: yogaLogger, +}); diff --git a/src/schema.ts b/src/yoga/schema.ts similarity index 100% rename from src/schema.ts rename to src/yoga/schema.ts diff --git a/tsconfig.json b/tsconfig.json index 238655f..c2f3b95 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,6 +22,15 @@ // Some stricter flags (disabled by default) "noUnusedLocals": false, "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false + "noPropertyAccessFromIndexSignature": false, + + // Path mapping + "baseUrl": ".", + "paths": { + "@app": ["./src"], + "@app/*": ["./src/*"], + "@lib": ["./lib"], + "@lib/*": ["./lib/*"] + } } }