mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Move apollo prom init into apollo.ts file
This commit is contained in:
parent
a52e8f7295
commit
e0ce598be5
2 changed files with 13 additions and 10 deletions
|
|
@ -7,6 +7,7 @@
|
|||
import { makeExecutableSchema } from '@graphql-tools/schema'
|
||||
import * as Sentry from '@sentry/node'
|
||||
import { ContextFunction, PluginDefinition } from 'apollo-server-core'
|
||||
import { Express } from 'express'
|
||||
import { ApolloServer } from 'apollo-server-express'
|
||||
import { ExpressContext } from 'apollo-server-express/dist/ApolloServer'
|
||||
import * as httpContext from 'express-http-context2'
|
||||
|
|
@ -26,6 +27,7 @@ import { getClaimsByToken, setAuthInCookie } from './utils/auth'
|
|||
import { SetClaimsRole } from './utils/dictionary'
|
||||
import { logger } from './utils/logger'
|
||||
import { ReadingProgressDataSource } from './datasources/reading_progress_data_source'
|
||||
import { createPrometheusExporterPlugin } from '@bmatei/apollo-prometheus-exporter'
|
||||
|
||||
const signToken = promisify(jwt.sign)
|
||||
const pubsub = createPubSubClient()
|
||||
|
|
@ -93,7 +95,7 @@ const contextFunc: ContextFunction<ExpressContext, ResolverContext> = async ({
|
|||
return ctx
|
||||
}
|
||||
|
||||
export function makeApolloServer(promExporter: PluginDefinition): ApolloServer {
|
||||
export function makeApolloServer(app: Express): ApolloServer {
|
||||
let schema = makeExecutableSchema({
|
||||
resolvers,
|
||||
typeDefs,
|
||||
|
|
@ -101,6 +103,15 @@ export function makeApolloServer(promExporter: PluginDefinition): ApolloServer {
|
|||
|
||||
schema = sanitizeDirectiveTransformer(schema)
|
||||
|
||||
const promExporter: PluginDefinition = createPrometheusExporterPlugin({
|
||||
app,
|
||||
hostnameLabel: false,
|
||||
defaultMetrics: false,
|
||||
defaultLabels: {
|
||||
service: 'api',
|
||||
},
|
||||
})
|
||||
|
||||
const apollo = new ApolloServer({
|
||||
schema: schema,
|
||||
context: contextFunc,
|
||||
|
|
|
|||
|
|
@ -168,15 +168,7 @@ export const createApp = (): {
|
|||
res.end(await prom.register.metrics())
|
||||
})
|
||||
|
||||
const promExporter = createPrometheusExporterPlugin({
|
||||
app,
|
||||
hostnameLabel: false,
|
||||
defaultMetrics: false,
|
||||
defaultLabels: {
|
||||
service: 'api',
|
||||
},
|
||||
})
|
||||
const apollo = makeApolloServer(promExporter)
|
||||
const apollo = makeApolloServer(app)
|
||||
const httpServer = createServer(app)
|
||||
|
||||
return { app, apollo, httpServer }
|
||||
|
|
|
|||
Loading…
Reference in a new issue