Skip to content

Commit a064516

Browse files
authored
feat(handler): add logger and graphiql to config options
1 parent d028d9e commit a064516

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

packages/pylon/src/app/handler/pylon-handler.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import {createSchema, createYoga} from 'graphql-yoga'
21
import {GraphQLScalarType, Kind} from 'graphql'
32
import {
43
DateTimeISOResolver,
54
GraphQLVoid,
65
JSONObjectResolver,
76
JSONResolver
87
} from 'graphql-scalars'
8+
import {createSchema, createYoga} from 'graphql-yoga'
99

10-
import {useSentry} from '../envelop/use-sentry'
11-
import {Context} from '../../context'
12-
import {resolversToGraphQLResolvers} from '../../define-pylon'
13-
import {PylonConfig} from '../..'
1410
import {readFileSync} from 'fs'
11+
import {logger} from 'hono/logger'
1512
import path from 'path'
13+
import {app, PylonConfig} from '../..'
14+
import {Context} from '../../context'
15+
import {resolversToGraphQLResolvers} from '../../define-pylon'
16+
import {useSentry} from '../envelop/use-sentry'
17+
import {graphqlViewerHandler} from './graphql-viewer-handler'
1618

1719
interface PylonHandlerOptions {
1820
graphql: {
@@ -117,6 +119,14 @@ export const handler = (options: PylonHandlerOptions) => {
117119
schema
118120
})
119121

122+
// Load middlewares based on config
123+
if (config?.logger !== false) {
124+
app.use('*', logger())
125+
}
126+
if (config?.graphiql !== false) {
127+
app.get('/viewer', graphqlViewerHandler)
128+
}
129+
120130
const handler = async (c: Context): Promise<Response> => {
121131
let executionContext: Context['executionCtx'] | {} = {}
122132

packages/pylon/src/app/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import {Hono} from 'hono'
2-
import {logger} from 'hono/logger'
32
import {sentry} from '@hono/sentry'
43

54
import {asyncContext, Env} from '../context'
6-
import {graphqlViewerHandler} from './handler/graphql-viewer-handler'
7-
85
export const app = new Hono<Env>()
96

107
app.use('*', sentry())
@@ -21,12 +18,8 @@ app.use('*', async (c, next) => {
2118
})
2219
})
2320

24-
app.use('*', logger())
25-
2621
app.use((c, next) => {
2722
// @ts-ignore
2823
c.req.id = crypto.randomUUID()
2924
return next()
3025
})
31-
32-
app.get('/viewer', graphqlViewerHandler)

packages/pylon/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ export {getEnv} from './get-env.js'
1818
export {createDecorator} from './create-decorator.js'
1919
export {createPubSub as experimentalCreatePubSub} from 'graphql-yoga'
2020

21-
export type PylonConfig = Pick<YogaServerOptions<Context, Context>, 'plugins'>
21+
export type PylonConfig = Pick<
22+
YogaServerOptions<Context, Context>,
23+
'plugins'
24+
> & {
25+
logger?: boolean
26+
graphiql?: boolean
27+
}
2228

2329
export type ID = string & {readonly brand?: unique symbol}
2430
export type Int = number & {readonly brand?: unique symbol}

0 commit comments

Comments
 (0)