basic setup with yoga + pothos and pino logger
This commit is contained in:
parent
f8a16a9fce
commit
6312b344cd
7 changed files with 52 additions and 10 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
19
lib/logger/index.ts
Normal file
19
lib/logger/index.ts
Normal file
|
|
@ -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);
|
||||
},
|
||||
};
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
19
src/index.ts
19
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}`);
|
||||
|
|
|
|||
8
src/yoga/index.ts
Normal file
8
src/yoga/index.ts
Normal file
|
|
@ -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,
|
||||
});
|
||||
|
|
@ -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/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue