fix time geneate logic and replace default datetime by luxon
This commit is contained in:
@@ -41,6 +41,7 @@ export type SchemaContext =
|
||||
res: Response
|
||||
me: User
|
||||
pubSub: PubSub
|
||||
invalidateCache: () => Promise<void>
|
||||
generator: PrismaCrudGenerator<BuilderTypes>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,12 @@ import { initContextCache } from '@pothos/core'
|
||||
...initContextCache(),
|
||||
isSubscription: false,
|
||||
http: {
|
||||
req,
|
||||
me: await graphqlService.acquireContext(req),
|
||||
invalidateCache: () =>
|
||||
graphqlService.invalidateCache(
|
||||
req.headers['x-session-id'] as string,
|
||||
),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
|
||||
@@ -37,6 +37,7 @@ export class GraphqlService {
|
||||
// redis context cache
|
||||
const cachedUser = await this.redis.getUser(sessionId)
|
||||
if (cachedUser) {
|
||||
Logger.log(`Cache hit for sessionId: ${sessionId}`)
|
||||
return cachedUser
|
||||
}
|
||||
// check if the token is valid
|
||||
@@ -53,4 +54,10 @@ export class GraphqlService {
|
||||
await this.redis.setUser(sessionId, user, session.expireAt)
|
||||
return user
|
||||
}
|
||||
|
||||
async invalidateCache(sessionId: string) {
|
||||
// invalidate redis cache for sessionId
|
||||
await this.redis.del(sessionId)
|
||||
Logger.log(`Invalidated cache for sessionId: ${sessionId}`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user