11import SchemaBuilder from "@pothos/core" ;
22import AuthzPlugin from "@pothos/plugin-authz" ;
33import DataloaderPlugin from "@pothos/plugin-dataloader" ;
4- import TracingPlugin , { wrapResolver } from "@pothos/plugin-tracing" ;
4+ import TracingPlugin , { isRootField } from "@pothos/plugin-tracing" ;
55import { DateResolver , DateTimeResolver } from "graphql-scalars" ;
66
77import * as rules from "~/authz" ;
8- import { createLogger } from "~/logging" ;
98import { Context } from "~/types" ;
109
11- const tracingLogger = createLogger ( "tracing" ) ;
12-
1310export const builder = new SchemaBuilder < {
1411 Context : Context ;
1512 AuthZRule : keyof typeof rules ;
@@ -26,13 +23,22 @@ export const builder = new SchemaBuilder<{
2623} > ( {
2724 plugins : [ TracingPlugin , AuthzPlugin , DataloaderPlugin ] ,
2825 tracing : {
29- default : ( ) => true ,
30- wrap : ( resolver , options , config ) =>
31- wrapResolver ( resolver , ( error , duration ) => {
32- tracingLogger . debug (
33- `[TRACING] ${ config . parentType } .${ config . name } in ${ duration } ms` ,
34- ) ;
35- } ) ,
26+ default : ( config ) => isRootField ( config ) ,
27+ wrap : ( resolver ) => {
28+ return async ( parent , args , context , info ) => {
29+ const start = Date . now ( ) ;
30+ const result = await resolver ( parent , args , context , info ) ;
31+ const duration = Date . now ( ) - start ;
32+
33+ context . logger . debug ( "[TRACING]" , {
34+ path : info . path ,
35+ duration,
36+ operation : info . operation ?. operation ,
37+ } ) ;
38+
39+ return result ;
40+ } ;
41+ } ,
3642 } ,
3743} ) ;
3844
0 commit comments