mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 10:07:35 +00:00
29 lines
696 B
TypeScript
29 lines
696 B
TypeScript
import { Router } from "express";
|
|
import { createYoga, YogaInitialContext } from "graphql-yoga";
|
|
|
|
// import DEFAULT_QUERY from "./defaultQuery";
|
|
import { getSchema } from "./schema";
|
|
import UserContext from "../../data/UserContext.js";
|
|
|
|
/** @gqlContext */
|
|
export type Ctx = Express.Request;
|
|
|
|
/** @gqlContext */
|
|
export function getUserContext(ctx: Ctx): UserContext {
|
|
return ctx.ctx;
|
|
}
|
|
|
|
const router = Router();
|
|
|
|
const yoga = createYoga({
|
|
schema: getSchema(),
|
|
context: (ctx: YogaInitialContext) => {
|
|
// @ts-expect-error
|
|
return ctx.req;
|
|
},
|
|
});
|
|
|
|
// Bind GraphQL Yoga to the graphql endpoint to avoid rendering the playground on any path
|
|
router.use("", yoga);
|
|
|
|
export default router;
|