Skip to content

Commit

Permalink
feat: added driveid to graphql context
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed Jan 22, 2024
1 parent d838b2c commit 675994f
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions api/src/graphql/context.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -16,6 +16,7 @@ export interface Context {
getSession: () => Promise<Session>;
apolloLogger: pino.Logger;
origin: string | undefined;
driveId?: string;
}

type CreateContextParams = {
Expand All @@ -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,
};
}

0 comments on commit 675994f

Please sign in to comment.