Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion apps/ensapi/src/omnigraph-api/yoga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,37 @@
// import { maxDepthPlugin } from "@escape.tech/graphql-armor-max-depth";
// import { maxTokensPlugin } from "@escape.tech/graphql-armor-max-tokens";

import { GraphQLError } from "graphql";
import { createYoga } from "graphql-yoga";
import { ZodError } from "zod/v4";

import { makeLogger } from "@/lib/logger";
import { context } from "@/omnigraph-api/context";
import { schema } from "@/omnigraph-api/schema";

const logger = makeLogger("omnigraph");

// tests exact ZodError or GraphQLError-wrapped ZodError
const isZodError = (value: unknown): boolean =>
value instanceof ZodError ||
(value instanceof GraphQLError && value.originalError instanceof ZodError);
Comment thread
shrugs marked this conversation as resolved.

// Yoga logs every execution error (including GraphQL input validation errors) at `error` level, but
// those validation errors are expected, in general, so we downgrade them to `debug` so server logs
// aren't flooded with stack traces.
const yogaLogger = {
debug: logger.debug.bind(logger),
info: logger.info.bind(logger),
warn: logger.warn.bind(logger),
error: (err: unknown, ..._rest: unknown[]) => {
if (isZodError(err)) {
logger.debug({ err }, "GraphQL input validation rejected");
return;
}
logger.error({ err }, "GraphQL execution error");
},
};
Comment thread
shrugs marked this conversation as resolved.

export const yoga = createYoga({
graphqlEndpoint: "*",
schema,
Expand All @@ -36,7 +59,7 @@ export const yoga = createYoga({
},

// integrate logging with pino
logging: logger,
logging: yogaLogger,

plugins: [
// TODO: plugins
Expand Down
Loading