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) {
|
constructor(private readonly prisma: PrismaClient) {
|
||||||
super({
|
super({
|
||||||
plugins: [PrismaPlugin, PrismaUtils, SimpleObjectPlugin, SmartSubscriptionPlugin, RelayPlugin, ErrorsPlugin, AuthzPlugin, ZodPlugin],
|
plugins: [
|
||||||
|
PrismaPlugin,
|
||||||
|
PrismaUtils,
|
||||||
|
SimpleObjectPlugin,
|
||||||
|
SmartSubscriptionPlugin,
|
||||||
|
RelayPlugin,
|
||||||
|
ErrorsPlugin,
|
||||||
|
AuthzPlugin,
|
||||||
|
ZodPlugin,
|
||||||
|
],
|
||||||
smartSubscriptions: {
|
smartSubscriptions: {
|
||||||
debounceDelay: 1000,
|
debounceDelay: 1000,
|
||||||
...subscribeOptionsFromIterator((name, context) => {
|
...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: {
|
zod: {
|
||||||
@@ -105,7 +116,9 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
|||||||
client: prisma,
|
client: prisma,
|
||||||
exposeDescriptions: true,
|
exposeDescriptions: true,
|
||||||
filterConnectionTotalCount: true,
|
filterConnectionTotalCount: true,
|
||||||
onUnusedQuery: process.env.NODE_ENV === 'production' ? null : 'warn',
|
onUnusedQuery: (info) => {
|
||||||
|
Logger.log(`Unused query: ${info.fieldName}`, 'GraphQL')
|
||||||
|
},
|
||||||
dmmf: getDatamodel(),
|
dmmf: getDatamodel(),
|
||||||
},
|
},
|
||||||
errors: {
|
errors: {
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ import { PubSubService } from 'src/PubSub/pubsub.service'
|
|||||||
if (!ctx.extra) {
|
if (!ctx.extra) {
|
||||||
throw new Error('No extra provided')
|
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']
|
ctx.extra.request.headers['x-session-id'] = ctx.connectionParams['x-session-id']
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user