From 675994fda2a2fefa0547f57447519060d7145555 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 22 Jan 2024 19:48:27 +0100 Subject: [PATCH] feat: added driveid to graphql context --- api/src/graphql/context.ts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/api/src/graphql/context.ts b/api/src/graphql/context.ts index 33c22e27..6d002831 100644 --- a/api/src/graphql/context.ts +++ b/api/src/graphql/context.ts @@ -1,13 +1,13 @@ -import type express from 'express'; -import pino from 'pino'; -import { Session } from '@prisma/client'; -import { getChildLogger } from '../logger'; -import { getExtendedPrisma } from '../importedModules'; +import type express from "express"; +import pino from "pino"; +import { Session } from "@prisma/client"; +import { getChildLogger } from "../logger"; +import { getExtendedPrisma } from "../importedModules"; -const logger = getChildLogger({ msgPrefix: 'CONTEXT' }); +const logger = getChildLogger({ msgPrefix: "CONTEXT" }); const apolloLogger = getChildLogger( - { msgPrefix: 'APOLLO' }, - { module: undefined }, + { msgPrefix: "APOLLO" }, + { module: undefined } ); export interface Context { @@ -16,6 +16,7 @@ export interface Context { getSession: () => Promise; apolloLogger: pino.Logger; origin: string | undefined; + driveId?: string; } type CreateContextParams = { @@ -25,19 +26,23 @@ type CreateContextParams = { }; export function createContext(params: CreateContextParams): Context { - logger.trace('Creating context with params: %o', params); + logger.trace("Creating context with params: %o", params); const { req } = params; - const authorizationHeader = req.get('Authorization'); - const cookieAuthHeader = req.cookies['gql:default']; - const token = authorizationHeader?.replace('Bearer ', ''); - const origin = req.get('Origin'); + const authorizationHeader = req.get("Authorization"); + const cookieAuthHeader = req.cookies["gql:default"]; + const token = authorizationHeader?.replace("Bearer ", ""); + const origin = req.get("Origin"); const prisma = getExtendedPrisma(); + const driveId = req.params.driveId; + return { request: params, prisma, apolloLogger, - getSession: async () => prisma.session.getSessionByToken(origin, token || cookieAuthHeader), + getSession: async () => + prisma.session.getSessionByToken(origin, token || cookieAuthHeader), origin, + driveId, }; }