Skip to content

Commit

Permalink
Add bemiContext, remove express dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Feb 29, 2024
1 parent 240d36c commit 06a1019
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"postgres-array": "^3.0.2"
},
"peerDependencies": {
"@prisma/client": "^5.9.1",
"express": "^4.18.2"
"@prisma/client": "^5.9.1"
},
"devDependencies": {
"@types/express": "^4.17.21",
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const withPgAdapter = <PrismaClientType>(originalPrisma: PrismaClientType
return prisma as PrismaClientType
}

// Next.js
export const setContext = (callback: (req: Request) => any) => {
return (req: Request, _res: Response, next: NextFunction) => {
const context = callback(req);
Expand All @@ -69,6 +70,7 @@ export const setContext = (callback: (req: Request) => any) => {
};
};

// Apollo Server
export const BemiApolloServerPlugin = (callback: (requestContext: any) => any) => {
return {
async requestDidStart(requestContext: any) {
Expand All @@ -77,3 +79,8 @@ export const BemiApolloServerPlugin = (callback: (requestContext: any) => any) =
},
}
}

// Other
export const bemiContext = (context: any) => {
ASYNC_LOCAL_STORAGE.enterWith(context);
}

0 comments on commit 06a1019

Please sign in to comment.