Upgrade apollo-server-express, remove connections/subscriptions
This commit is contained in:
@ -56,7 +56,7 @@
|
||||
"@types/voca": "^1.4.0",
|
||||
"analytics-node": "^6.0.0",
|
||||
"apollo-datasource": "^0.7.2",
|
||||
"apollo-server-express": "^2.25.3",
|
||||
"apollo-server-express": "^3.6.3",
|
||||
"axios": "^0.26.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"cookie": "^0.4.1",
|
||||
|
||||
@ -45,10 +45,8 @@ const schemaDirectives = {
|
||||
const contextFunc: ContextFunction<ExpressContext, ResolverContext> = async ({
|
||||
req,
|
||||
res,
|
||||
connection,
|
||||
}) => {
|
||||
let claims: Claims | undefined
|
||||
const isSubscription = !!connection
|
||||
|
||||
const token = req?.cookies?.auth || req?.headers?.authorization
|
||||
|
||||
@ -59,14 +57,8 @@ const contextFunc: ContextFunction<ExpressContext, ResolverContext> = async ({
|
||||
|
||||
if (token && jwt.verify(token, env.server.jwtSecret)) {
|
||||
claims = jwt.decode(token) as Claims
|
||||
} else if (connection) {
|
||||
const wsToken =
|
||||
connection?.context?.cookies?.auth ||
|
||||
connection?.context?.headers?.authorization
|
||||
if (wsToken && jwt.verify(wsToken, env.server.jwtSecret)) {
|
||||
claims = jwt.decode(wsToken) as Claims
|
||||
}
|
||||
}
|
||||
|
||||
async function setClaims(
|
||||
tx: Transaction,
|
||||
uuid?: string,
|
||||
@ -87,7 +79,7 @@ const contextFunc: ContextFunction<ExpressContext, ResolverContext> = async ({
|
||||
// no caching for subscriptions
|
||||
// TODO: create per request caching for connections
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
models: initModels(kx, !isSubscription),
|
||||
models: initModels(kx, true),
|
||||
clearAuth: () => {
|
||||
res.clearCookie('auth')
|
||||
res.clearCookie('pendingUserAuth')
|
||||
@ -116,14 +108,6 @@ const contextFunc: ContextFunction<ExpressContext, ResolverContext> = async ({
|
||||
tracingSpan: tracer.startSpan('apollo.request'),
|
||||
}
|
||||
|
||||
if (connection) {
|
||||
return {
|
||||
...connection.context,
|
||||
...ctx,
|
||||
userRole: claims?.userRole,
|
||||
uid: claims ? claims.uid : null,
|
||||
}
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
|
||||
@ -40,15 +40,12 @@ export type DataModels = {
|
||||
reminder: ReminderModel
|
||||
}
|
||||
|
||||
export type DataSources = unknown
|
||||
|
||||
export interface RequestContext {
|
||||
log: winston.Logger
|
||||
claims: Claims | undefined
|
||||
kx: Knex
|
||||
pubsub: PubsubClient
|
||||
models: DataModels
|
||||
dataSources: DataSources
|
||||
setAuth: (claims: ClaimsToSet, secret?: string) => Promise<void>
|
||||
clearAuth: () => void
|
||||
setClaims: (tx: Knex.Transaction, uuid?: string | undefined) => Promise<void>
|
||||
|
||||
@ -113,7 +113,6 @@ export const createApp = (): {
|
||||
|
||||
const apollo = makeApolloServer(app)
|
||||
const httpServer = createServer(app)
|
||||
apollo.installSubscriptionHandlers(httpServer)
|
||||
|
||||
return { app, apollo, httpServer }
|
||||
}
|
||||
@ -136,7 +135,6 @@ const main = async (): Promise<void> => {
|
||||
const listener = httpServer.listen({ port: PORT }, async () => {
|
||||
const logger = buildLogger('app.dispatch')
|
||||
logger.notice(`🚀 Server ready at ${apollo.graphqlPath}`)
|
||||
logger.notice(`🚀 WS Server ready at ${apollo.subscriptionsPath}`)
|
||||
})
|
||||
|
||||
// Avoid keepalive timeout-related connection drops manifesting in user-facing 502s.
|
||||
|
||||
Reference in New Issue
Block a user