refactor: improve code readability and logging in GraphQL builder
- Reformat plugin array for better readability in the Builder class constructor. - Enhance unused query handling by adding logging for unused queries in development. - Update TypeScript error comment for clarity in GraphqlModule, specifying that the request is not typed.
This commit is contained in:
@@ -85,11 +85,22 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
||||
|
||||
constructor(private readonly prisma: PrismaClient) {
|
||||
super({
|
||||
plugins: [PrismaPlugin, PrismaUtils, SimpleObjectPlugin, SmartSubscriptionPlugin, RelayPlugin, ErrorsPlugin, AuthzPlugin, ZodPlugin],
|
||||
plugins: [
|
||||
PrismaPlugin,
|
||||
PrismaUtils,
|
||||
SimpleObjectPlugin,
|
||||
SmartSubscriptionPlugin,
|
||||
RelayPlugin,
|
||||
ErrorsPlugin,
|
||||
AuthzPlugin,
|
||||
ZodPlugin,
|
||||
],
|
||||
smartSubscriptions: {
|
||||
debounceDelay: 1000,
|
||||
...subscribeOptionsFromIterator((name, context) => {
|
||||
return context.isSubscription ? context.websocket.pubSub.asyncIterator(name) : context.http.pubSub.asyncIterator(name)
|
||||
return context.isSubscription
|
||||
? context.websocket.pubSub.asyncIterator(name)
|
||||
: context.http.pubSub.asyncIterator(name)
|
||||
}),
|
||||
},
|
||||
zod: {
|
||||
@@ -105,7 +116,9 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
||||
client: prisma,
|
||||
exposeDescriptions: true,
|
||||
filterConnectionTotalCount: true,
|
||||
onUnusedQuery: process.env.NODE_ENV === 'production' ? null : 'warn',
|
||||
onUnusedQuery: (info) => {
|
||||
Logger.log(`Unused query: ${info.fieldName}`, 'GraphQL')
|
||||
},
|
||||
dmmf: getDatamodel(),
|
||||
},
|
||||
errors: {
|
||||
|
||||
@@ -114,7 +114,7 @@ import { PubSubService } from 'src/PubSub/pubsub.service'
|
||||
if (!ctx.extra) {
|
||||
throw new Error('No extra provided')
|
||||
}
|
||||
// @ts-expect-error: TODO
|
||||
// @ts-expect-error: Request is not typed
|
||||
ctx.extra.request.headers['x-session-id'] = ctx.connectionParams['x-session-id']
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user