add yoga logger

This commit is contained in:
Benjamin Palko 2024-12-10 10:09:20 -05:00
parent e06dc1ec94
commit 21634249d7
4 changed files with 28 additions and 1 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -52,6 +52,8 @@
"@tailwindcss/typography": "^0.5.15", "@tailwindcss/typography": "^0.5.15",
"graphql": "^16.9.0", "graphql": "^16.9.0",
"graphql-yoga": "^5.10.4", "graphql-yoga": "^5.10.4",
"pino": "^9.5.0",
"pino-pretty": "^13.0.0",
"storybook-dark-mode": "^4.0.2" "storybook-dark-mode": "^4.0.2"
} }
} }

23
src/lib/logger/index.ts Normal file
View file

@ -0,0 +1,23 @@
import { type YogaLogger } from 'graphql-yoga';
import pino from 'pino';
export const logger = pino();
export const yogaLogger: YogaLogger = {
debug(...args) {
// @ts-expect-error types dont match
logger.debug(...args);
},
info(...args) {
// @ts-expect-error types dont match
logger.info(...args);
},
warn(...args) {
// @ts-expect-error types dont match
logger.warn(...args);
},
error(...args) {
// @ts-expect-error types dont match
logger.error(...args);
}
};

View file

@ -1,3 +1,4 @@
import { yogaLogger } from '$lib/logger';
import { Schema } from '$lib/pothos'; import { Schema } from '$lib/pothos';
import type { RequestEvent } from '@sveltejs/kit'; import type { RequestEvent } from '@sveltejs/kit';
import { createYoga } from 'graphql-yoga'; import { createYoga } from 'graphql-yoga';
@ -6,5 +7,6 @@ export const Yoga = createYoga<RequestEvent>({
schema: Schema, schema: Schema,
graphqlEndpoint: '/api/graphql', graphqlEndpoint: '/api/graphql',
// Let Yoga use sveltekit's Response object // Let Yoga use sveltekit's Response object
fetchAPI: { Response } fetchAPI: { Response },
logging: yogaLogger
}); });