@@ -6,7 +6,7 @@ import { expect } from 'chai';
66
77import { invariant } from '../jsutils/invariant.ts' ;
88
9- import type { MinimalTracingChannel } from '../diagnostics.ts' ;
9+ import type { MinimalChannel , MinimalTracingChannel } from '../diagnostics.ts' ;
1010import {
1111 executeChannel ,
1212 executeRootSelectionSetChannel ,
@@ -54,6 +54,38 @@ describe('diagnostics', () => {
5454 } ) ;
5555
5656 describe ( 'shouldTrace' , ( ) => {
57+ function makeSubChannel ( hasSubscribers : boolean ) : MinimalChannel {
58+ return {
59+ hasSubscribers,
60+ publish : ( ) => undefined ,
61+ runStores < T , ContextType extends object > (
62+ context : ContextType ,
63+ fn : ( this : ContextType , ...args : Array < unknown > ) => T ,
64+ ) : T {
65+ return fn . call ( context ) ;
66+ } ,
67+ } ;
68+ }
69+
70+ function makeFallbackTracingChannel (
71+ subscribedSubChannel ?: keyof Pick <
72+ MinimalTracingChannel ,
73+ 'start' | 'end' | 'asyncStart' | 'asyncEnd' | 'error'
74+ > ,
75+ ) : MinimalTracingChannel {
76+ return {
77+ hasSubscribers : undefined ,
78+ start : makeSubChannel ( subscribedSubChannel === 'start' ) ,
79+ end : makeSubChannel ( subscribedSubChannel === 'end' ) ,
80+ asyncStart : makeSubChannel ( subscribedSubChannel === 'asyncStart' ) ,
81+ asyncEnd : makeSubChannel ( subscribedSubChannel === 'asyncEnd' ) ,
82+ error : makeSubChannel ( subscribedSubChannel === 'error' ) ,
83+ traceSync < T > ( fn : ( ...args : Array < unknown > ) => T ) : T {
84+ return fn ( ) ;
85+ } ,
86+ } ;
87+ }
88+
5789 it ( 'returns false when channel is undefined' , ( ) => {
5890 expect ( shouldTrace ( undefined ) ) . to . equal ( false ) ;
5991 } ) ;
@@ -79,5 +111,10 @@ describe('diagnostics', () => {
79111 realTC . unsubscribe ( handler ) ;
80112 }
81113 } ) ;
114+
115+ it ( 'falls back to sub-channel subscribers when aggregate is missing' , ( ) => {
116+ expect ( shouldTrace ( makeFallbackTracingChannel ( 'error' ) ) ) . to . equal ( true ) ;
117+ expect ( shouldTrace ( makeFallbackTracingChannel ( ) ) ) . to . equal ( false ) ;
118+ } ) ;
82119 } ) ;
83120} ) ;
0 commit comments